Bug with SwordfishSE PIC18F46K22? (works with PICBASIC PRO)

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Mawbert
Posts: 13
Joined: Tue Dec 27, 2011 4:14 pm
Location: USA

Bug with SwordfishSE PIC18F46K22? (works with PICBASIC PRO)

Post by Mawbert » Tue Dec 27, 2011 9:04 pm

I have a problem with Swordfish that I cannot resolve and that seems like a bug to me. Perhaps the device files?

I have written the same program in both SwordfishSE (still waiting for help with my pro version update not recognizing my serial number) and PICBASIC PRO to test inputs PORTB.3 and PORTA.5 and to buzz a buzzer to indicate the result. The test circuit is as follows.

Image

PICBASIC PRO works fine but Swordfish does not read PORTA.5 (or any of the PORTE ports that I tested too). I was hoping to use Swordfish as it seems like a stronger language but I may have to use PICBASIC PRO. C is out of the question for me.

Here are the two programs. (By the way I am not a professional developer).

SWORDFISH:

Code: Select all

Device = 18F46K22

Clock = 4

//FOSC(FOSC) = [LP, XT, HSHP, HSMP, ECHP, ECHPIO6, RC, RCIO6, INTIO67, INTIO7, ECMP, ECMPIO6, ECLP, ECLPIO6]
Config FOSC = HSMP
Config WDTEN = OFF
Config PWRTEN = ON
Config BOREN = OFF
Config PBADEN = OFF
Config MCLRE = INTMCLR
Config LVP = OFF
Config DEBUG = OFF
Config XINST = OFF



Dim SW1 As PORTB.3          // SW1 THIS WORKS AND TOGGLES THE BUZZER
Dim SW2 As PORTA.5          // SW2 input switch THIS MAKES NO DIFFERENCE AND DOES NOT TOGGLE THE BUZZER
Dim Buzzer As PORTA.4       // buzzer output
Dim SW1_Power As PORTA.2    // power the switches
Dim SW2_Power As PORTB.5    //

ANSELA = 0 // All Digital
ANSELB = 0
ANSELC = 0
ANSELD = 0
ANSELE = 0
TRISB.3 = 1
TRISA.5 = 1


// make SW1 and SW2 inputs
Input(SW1)
Input(SW2)

// main program...

High(SW1_Power)
High(SW2_Power)

Low(Buzzer)
Repeat
  While SW1 = 1 or SW2 = 1     // ONLY SW1 makes the buzzer buzz
       Toggle (Buzzer)
       DelayUS (600)
  Wend
Low(Buzzer)
Until false

PICBASIC PRO

Code: Select all

DEFINE OSC 4

#config
CONFIG FOSC = HSMP
CONFIG WDTEN = OFF
CONFIG PWRTEN = ON
CONFIG BOREN = OFF
CONFIG PBADEN = OFF
CONFIG MCLRE = INTMCLR
CONFIG LVP = OFF
CONFIG DEBUG = OFF
CONFIG XINST = OFF
#endconfig

SW1 var PORTB.3         ' SW1 THIS WORKS AND TOGGLES THE BUZZER
SW2 var PORTA.5         ' SW1 THIS WORKS AND TOGGLES THE BUZZER
Buzzer var PORTA.4      ' buzzer output
SW1_Power var PORTA.2   ' Power the variable selector switch
SW2_Power var PORTB.5

ANSELA = 0 ; All Digital
ANSELB = 0
ANSELC = 0
ANSELD = 0
ANSELE = 0
TRISB.3 = 1
TRISA.5 = 1

mainloop:

   high SW1_Power
   High SW2_Power
   
   low Buzzer
   DO
      While SW1 = 1 or SW2 = 1      'Either switch makes the buzzer buzz
           FREQOUT Buzzer,2000,2500
      Wend
   low Buzzer          
   loop
   
   End
Any suggestions would be much appreciated. I have also tried using the updated setdigitalio but that did not help either.

Thanks
Beginner

bitfogav
Registered User
Registered User
Posts: 169
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Post by bitfogav » Tue Dec 27, 2011 11:58 pm

If you are using the SE version of Swordfish then you will have to use the "setdigitalio.bas" to setup the 18F46K22 PORTS correctly, since SE does not contain code to set the bank select register.

So since SE does not contain code to set the bank select register, setting "#option SWORDFISH_SE = true" will enable the write_sfr()/read_sfr() macros to generate a MOVFF instruction so that setting the BSR is not required.

So you will need to add this line of code to your swordfish SE code

Code: Select all

#option SWORDFISH_SE = true
Try this Code: (but make sure you have copied SetAllDigital.bas to the user library folder) and Ive also changed some of your code so both switches should work now when pressed.

Code: Select all

Device = 18F46K22 

Clock = 4 

//FOSC(FOSC) = [LP, XT, HSHP, HSMP, ECHP, ECHPIO6, RC, RCIO6, INTIO67, INTIO7, ECMP, ECMPIO6, ECLP, ECLPIO6] 
Config FOSC = HSMP, 
      WDTEN = OFF, 
      PWRTEN = ON,
      BOREN = OFF, 
      PBADEN = OFF, 
      MCLRE = INTMCLR, 
      LVP = OFF, 
      DEBUG = OFF, 
      XINST = OFF 


#option SWORDFISH_SE = true

Include "SetDigitalIO.bas"

Dim SW1 As PORTB.3          // SW1 THIS WORKS AND TOGGLES THE BUZZER 
Dim SW2 As PORTA.5          // SW2 input switch THIS MAKES NO DIFFERENCE AND DOES NOT TOGGLE THE BUZZER 
Dim Buzzer As PORTA.4       // buzzer output 
Dim SW1_Power As PORTA.2    // power the switches 
Dim SW2_Power As PORTB.5    // 

// set all analog IO pins to digital function
SetAllDigital() 
TRISB.3 = 1 
TRISA.5 = 1 

// make SW1 and SW2 inputs 
Input(SW1) 
Input(SW2) 

// main program... 

High(SW1_Power) 
High(SW2_Power) 

Low(Buzzer) 
While true 
  If SW1 = 1 Or SW2 = 1 Then     // ONLY SW1 makes the buzzer buzz 
       Toggle (Buzzer) 
       DelayUS (600) 
  EndIf 
Low(Buzzer) 
Wend

Mawbert
Posts: 13
Joined: Tue Dec 27, 2011 4:14 pm
Location: USA

Post by Mawbert » Wed Dec 28, 2011 1:44 am

Thanks for taking the time to reply. Very much appreciated. I cut and pasted your code verbatim. The SetAllDigital.bas in my user folder is the following. As noted above I had tried using SetAllDigital() before with no joy.

Unfortunately neither of the switches work now? Are you saying that the PRO version should work? It would really help not to have to play with the libraries since I do not have the necessary background. I actually have a PRO license but when I tried to update it using the link David sent me it gave me an error message saying the the key was not recognized. I think David is on vacation as I am yet to hear back from him on how to fix it

Code: Select all

{
****************************************************************************
* Name    : SetAllDigital                                                  *
* Purpose : Switches device pins from analog to digital                    *
* Version : 1.6                                                            *
* Notes   :                                                                *
*         : 1.6 - change 18FxxK22 (rickado)                                *
*         :       correct 18F1230/1330 comparator setting                  *
*         : 1.5 - add 18F4xK22 (rickado)                                   *
*         : 1.4 - add write_sfr()/read_sfr() macros and add'tl devices     *
*         :       add #option SWORDFISH_SE                                 *
*         : 1.3 - add fix for ADSHR shared SFR registers (certain J series)*
*         : 1.2 - add 18FxxK20, K22, K50, K80, and K90 series              *
*         : 1.1 - add 18F46J50                                             *
****************************************************************************
}
Module SetDigitalIO

// set this option true if building with the SE compiler
#option SWORDFISH_SE = true

//
// these macros are used to read and write SFR's that are located in the upper
// bank (bank 15), but are not part of the access bank
//
// since SE does not contain code to set the bank select register, setting
// #option SWORDFISH_SE true will enable the write_sfr()/read_sfr() macros to
// generate a MOVFF instruction so that setting the BSR is not required
//
Public Macro write_sfr(sfr, val)
  #if (SWORDFISH_SE)
    WREG = val
    Asm
        movff wreg, sfr
    End Asm
  #else
    sfr = val
  #endif
End Macro

Public Macro read_sfr(sfr, bvar)
  #if (SWORDFISH_SE)
    Asm
        movff sfr, bvar
    End Asm
  #else
    bvar = sfr
  #endif
End Macro

//
// set all analog IO pins to digital function
//
Public Sub SetAllDigital()

  Dim ADSHR As WDTCON.4         // alternate register address bit present on certain devices

  // devices are grouped by datasheet where appropriate

  // 4 channels
  #if _device in (18F1230, 18F1330)
    ADCON1 = $00
    CMCON = $00         // changed V1.6

  // 5 channels, ANSEL...
  #elseif _device in (18F2331, 18F2431)
    ANSEL0 = $00

  // 9 channels, ANSEL...
  #elseif _device in (18F4331, 18F4431)
    ANSEL0 = $00
    ANSEL1.0 = 0

  // 7 channels, bit field...
  #elseif _device in (18F1220, 18F1320)
    ADCON1 = $7F

  // J10/J15 family...
  #elseif _device in (18F65J10, 18F65J15, 18F66J10, 18F66J15, 18F67J10, 18F85J10, 18F85J15, 18F86J10, 18F86J15, 18F87J10)
    ADCON1 = $0F
    CMCON = 0

  // J11 family...
  #elseif _device in (18F63J11, 18F64J11, 18F65J11, 18F83J11, 18F84J11, 18F85J11)
    ADCON1 = $0F
    CMCON = 0

  // J11 family... (shared SFR addresses)
  #elseif _device in (18F66J11, 18F67J11, 18F86J11, 18F87J11)
    // registers $0F5A - $0F5F are not part of the access bank
    ADSHR = 1
    ANCON0 = $FF
    ANCON1 = $FF
    ADSHR = 0
    CM1CON = 0
    CM2CON = 0

  // J16 family... (shared SFR addresses)
  #elseif _device in (18F66J16, 18F86J16)
    // registers $0F5A - $0F5F are not part of the access bank
    ADSHR = 1
    ANCON0 = $FF
    ANCON1 = $FF
    ADSHR = 0
    CM1CON = 0
    CM2CON = 0

  // J50 family... (shared SFR addresses)
  #elseif _device in (18F65J50, 18F66J50, 18F67J50, 18F85J50, 18F86J50, 18F87J50)
    // registers $0F40 - $0F5F are not part of the access bank
    ADSHR = 1
    ANCON0 = $FF
    ANCON1 = $FF
    ADSHR = 0
    CM1CON = 0
    CM2CON = 0

  // J55 family... (shared SFR addresses)
  #elseif _device in (18F66J55, 18F86J55)
    // registers $0F40 - $0F5F are not part of the access bank
    ADSHR = 1
    ANCON0 = $FF
    ANCON1 = $FF
    ADSHR = 0
    CM1CON = 0
    CM2CON = 0

  // J50 family...
  #elseif _device in (18F24J50, 18F25J50, 18F26J50, 18F44J50, 18F45J50, 18F46J50)
    // registers $0EC0 - $0F5F are not part of the access bank
    write_sfr(ANCON0, $FF)
    write_sfr(ANCON1, $1F)
    CM1CON = 0
    CM2CON = 0

  // J53 family...
  #elseif _device in (18F26J53, 18F27J53, 18F46J53, 18F47J53)
    // registers $0EB0 - $0F5F are not part of the access bank
    write_sfr(ANCON0, $FF)
    write_sfr(ANCON1, $1F)
    CM1CON = 0
    CM2CON = 0

  // 18FxxK20 family
  #elseif _device in (18F23K20, 18F24K20, 18F25K20, 18F26K20, 18F43K20, 18F44K20, 18F45K20, 18F46K20)
    ANSEL = $00
    ANSELH = $00
    CM1CON0 = 0
    CM2CON0 = 0

  // 18FxxK22 family
  // 18F1xK22
  #elseif _device in (18F13K22, 18F14K22)
    // registers $0F53 - $0F5F are not part of the access bank
    ANSEL = $00
    ANSELH = $00
    CM1CON0 = 0
    CM2CON0 = 0
    VREFCON1 = $00              // added V1.6

  // 18F2xK22/18F4xK22
  #elseif _device in (18F23K22, 18F24K22, 18F25K22, 18F26K22)
    // registers $0F38 - $0F5F are not part of the access bank
    write_sfr(ANSELA, $00)
    write_sfr(ANSELB, $00)
    write_sfr(ANSELC, $00)
    CM1CON0 = %00001000         // changed V1.6
    CM2CON0 = %00001000
    VREFCON1 = $00              // added V1.6

  #elseif _device in (18F43K22, 18F44K22, 18F45K22, 18F46K22)    // added V1.5
    // registers $0F38 - $0F5F are not part of the access bank
    write_sfr(ANSELA, $00)
    write_sfr(ANSELB, $00)
    write_sfr(ANSELC, $00)
    write_sfr(ANSELD, $00)
    write_sfr(ANSELE, $00)
    CM1CON0 = %00001000         // changed V1.6
    CM2CON0 = %00001000
    VREFCON1 = $00              // added V1.6

  // 18F87K22 family
  #elseif _device in (18F65K22, 18F66K22, 18F67K22, 18F85K22, 18F86K22, 18F87K22)
    // registers $0F16 - $0F5F are not part of the access bank
    write_sfr(ANCON0, $00)
    write_sfr(ANCON1, $00)
    write_sfr(ANCON2, $00)
    CM1CON = 0
    CM2CON = 0
    CM3CON = 0
    CVRCON = $00                // added V1.6

  // 18FxxK50 family
  #elseif _device in (18F13K50, 18F14K50)
    // registers $0F53 - $0F5F are not part of the access bank
    ANSEL = $00
    ANSELH = $00
    CM1CON0 = 0
    CM2CON0 = 0

  // 18FxxK80 family
  #elseif _device in (18F25K80, 18F26K80, 18F45K80, 18F46K80, 18F65K80, 18F66K80)
    // registers $0E41 - $0F5F are not part of the access bank
    write_sfr(ANCON0, $00)
    write_sfr(ANCON1, $00)
    write_sfr(CM1CON, $00)
    write_sfr(CM2CON, $00)

  // 18FxxK90 family
  #elseif _device in (18F65K90, 18F66K90, 18F67K90, 18F85K90, 18F86K90, 18F87K90)
    // registers $0EF4 - $0F5F are not part of the access bank
    write_sfr(ANCON0, $00)
    write_sfr(ANCON1, $00)
    write_sfr(ANCON2, $00)
    write_sfr(CM1CON, $00)
    write_sfr(CM2CON, $00)
    write_sfr(CM3CON, $00)

  // 8 - 13 channels - 0 comp
  #elseif _comparator = 0
    ADCON1 = $0F

  // assume default is ok...
  #else
    ADCON1 = $0F
    CMCON = $07
  #endif
End Sub

End Module 
Beginner

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Wed Dec 28, 2011 2:30 am

In your schematic VDD should be 3V3 and VSS should be GND.

When you depress one of the switches, it will short the pullup low, so you must be testing for SW1=0 or SW2=0 to detect a press.

The SE version of Swordfish can take a bit of extra work with some of these chips since (as pointed out) it doesn't contain any code to select RAM banks. The real version beats PBP hands down.

bitfogav
Registered User
Registered User
Posts: 169
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Post by bitfogav » Wed Dec 28, 2011 2:38 am

Thanks for pointing that out Jerry. :)

So your code for reading the switches should be:

Code: Select all

  If SW1 = 0 Or SW2 = 0 Then     
       Toggle (Buzzer) 
       DelayUS (600) 
  EndIf 

Mawbert
Posts: 13
Joined: Tue Dec 27, 2011 4:14 pm
Location: USA

Post by Mawbert » Wed Dec 28, 2011 3:53 am

Thanks for the help but unfortunately that is not it. The latest program does not work at all.

i.e. with

Code: Select all

If SW1 = 0 Or SW2 = 0 Then
or with

Code: Select all

If SW1 = 1 Or SW2 = 1 Then
The buzzer does not turn on regardless of the state of the switches. It appears that the latest code broke something else too.

They are not momentary switches. It does not work regardless of the state of the switches. Note too that the PICBASIC PRO code works just fine so it is very unlikely to be the circuit.
Last edited by Mawbert on Wed Dec 28, 2011 4:04 am, edited 1 time in total.
Beginner

Mawbert
Posts: 13
Joined: Tue Dec 27, 2011 4:14 pm
Location: USA

Post by Mawbert » Wed Dec 28, 2011 4:03 am

You are are correct though in noticing my mistake in the drawing VSS and VDD are reversed in error - sorry about that. The actual circuit is correct and my drawing is wrong. Here is the corrected drawing.

Image
Beginner

Mawbert
Posts: 13
Joined: Tue Dec 27, 2011 4:14 pm
Location: USA

Post by Mawbert » Wed Dec 28, 2011 4:16 am

I also happen to have a license for the real version and would love to get it to work. Unfortunately when I try and update it I get this message. I have double checked my key, verified the dongle is being read, and have even taken a photo of the product key on the disk cover and sent it in to support for help. I have also tried on two different computers with the same result.

Image

The Swordfish syntax looks great but I am 0 for 2 so far.

I appreciate the help.
Beginner

bitfogav
Registered User
Registered User
Posts: 169
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Post by bitfogav » Wed Dec 28, 2011 12:16 pm

Your switches in your diagram are also wrongly connected then, when you press any switch, the switches are connected to GND so this makes the input a logic 0, but your actually testing the input for logic 1 when any of the switches are pressed?.

Anyway as for the compiler being updated then David will have to look at this for you, the Dongles that was originally used for security for the compiler are not used anymore with the new version of the compiler.

Right then for now try starting a new project in the SE version of swordfish and copy this code and compile it and see if this works? it compiles fine with me but I dont have a 18F46K22 handy to test.


Code: Select all

Device = 18F46K22 

Clock = 4 

//FOSC(FOSC) = [LP, XT, HSHP, HSMP, ECHP, ECHPIO6, RC, RCIO6, INTIO67, INTIO7, ECMP, ECMPIO6, ECLP, ECLPIO6] 
Config FOSC = HSMP, 
      WDTEN = OFF, 
      PWRTEN = ON, 
      BOREN = OFF, 
      PBADEN = OFF, 
      MCLRE = INTMCLR, 
      LVP = OFF, 
      DEBUG = OFF, 
      XINST = OFF 


Dim SW1 As PORTB.3          // SW1 THIS WORKS AND TOGGLES THE BUZZER 
Dim SW2 As PORTA.5          // SW2 input switch THIS MAKES NO DIFFERENCE AND DOES NOT TOGGLE THE BUZZER 
Dim Buzzer As PORTA.4       // buzzer output 
Dim SW1_Power As PORTA.2    // power the switches 
Dim SW2_Power As PORTB.5    // 


// macro used to write SFR's that are located in the upper 
// bank (bank 15), but are not part of the access bank.
Macro write_sfr(sfr, val) 
    WREG = val 
    Asm 
        movff wreg, sfr 
    End Asm 
End Macro 

// set all analog IO pins to digital function  
write_sfr(ANSELA, $00) 
write_sfr(ANSELB, $00) 
write_sfr(ANSELC, $00) 
write_sfr(ANSELD, $00) 
write_sfr(ANSELE, $00) 
CM1CON0 = %00001000      
CM2CON0 = %00001000 
VREFCON1 = $00 

// make SW1 and SW2 inputs 
Input(SW1) 
Input(SW2)
// make sure Buzzer is set for output
output(buzzer)

// main program... 
High(SW1_Power) 
High(SW2_Power) 
Low(Buzzer) 

While true 
      If SW1 = 1 Or SW2 = 1 Then    
           high(Buzzer) 
           DelayUS (600) 
      EndIf 
    Low(Buzzer) 
Wend

Mawbert
Posts: 13
Joined: Tue Dec 27, 2011 4:14 pm
Location: USA

Post by Mawbert » Wed Dec 28, 2011 1:30 pm

Thanks. I tried this code with the same result. No response to the switches. (I think in an earlier attempt I had tried to blindly paste a similar snippet of code from setdigitalio.bas with no luck. I have very limited understanding of SFR and bank switching and was hoping to avoid the complexity.)

Sorry about the switch confusion. They are on/off switches not momentary push button switches. I am testing with them normally closed i.e. 0 and then switching SW1 or SW2 open i.e. 1 to see if the code reads the high and buzzes the buzzer (I could have used a LED but a buzzer was already part of the design). The PICBASIC PRO code works as expected. Open any one of the switches and the buzzer buzzes. My first Swordfish sample responds to SW1 open (PORTB.3) but not SW2 open (PORTA.5).

Using other code, I can also successfully read the ADC from both Swordfish and PBP using AN11 and send the result out via hardware uart 2 at 9600 baud. (I found I had to switch to the internal OSC at 16MHz to get the 9600 serial to work correctly with BPB.) I can also toggle pins PORTD.4 and PORTD.5 with both compilers. I simply cannot get SE to correctly read PORTA.5 or PORTE.0 or PORTE.1 or PORTE.2. I actually have a dip switch connected to these 4 pins but did not send the entire circuit to avoid confusion. I know the circuit works as I can read all these pins using PBP.

I can include other sample code if needed but I was trying to create a really simple example that isolated the issue for testing.

Thanks again for the help.
Beginner

Mawbert
Posts: 13
Joined: Tue Dec 27, 2011 4:14 pm
Location: USA

Post by Mawbert » Wed Dec 28, 2011 1:49 pm

I also just found this post:

http://www.sfcompiler.co.uk/forum/viewt ... t=18f46k22
Beware when converting pic18f46k22.

In 18F46K22.bas file
#variable _maxram = $0F60 // 3936 bytes of user RAM

will have to be changed to
#variable _maxram = $0F38 // 3896 bytes of user RAM from DataSheet
My PIC18F46K22 has #variable _maxram = $0F60 // 3936 bytes of user RAM

Perhaps this is worth trying but I am not sure how to change it? Putting a new PIC18F46K22.bas in my user directory did not seem to default to it in the IDE explorer.
Beginner

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Wed Dec 28, 2011 3:37 pm

Probably not worth the bother. The SE version will only use one RAM bank (BANK0), so it doesn't matter what that setting is.

I don't have any hardware with me at the moment, but that code is pretty simple. I don't see where it could be going wrong.

You aren't using a bootloader by chance to program the chip are you?

Mawbert
Posts: 13
Joined: Tue Dec 27, 2011 4:14 pm
Location: USA

Post by Mawbert » Wed Dec 28, 2011 3:52 pm

No bootloader. I am programming the hex using a PICKIT2.

btw - I misspoke when I said I had the ADC working on with PBP. I am confusing myself. I am reading the digital inputs just fine with PBP but have not yet worked out the ADC settings for PBP using the 18FK22.

David just sent me new instructions for the licensed version. I will see if I can install it any maybe this problem will go away.

I will keep you updated.

Thanks again for all the help.
Beginner

Mawbert
Posts: 13
Joined: Tue Dec 27, 2011 4:14 pm
Location: USA

Post by Mawbert » Wed Dec 28, 2011 4:12 pm

I have just updated my licensed version of Swordfish and tried my original program below. No setdigitalio. It works! There is clearly an issue with SE.

Code: Select all

Device = 18F46K22

Clock = 4

//FOSC(FOSC) = [LP, XT, HSHP, HSMP, ECHP, ECHPIO6, RC, RCIO6, INTIO67, INTIO7, ECMP, ECMPIO6, ECLP, ECLPIO6]
Config FOSC = HSMP
Config WDTEN = OFF
Config PWRTEN = ON
Config BOREN = OFF
Config PBADEN = OFF
Config MCLRE = INTMCLR
Config LVP = OFF
Config DEBUG = OFF
Config XINST = OFF



Dim SW1 As PORTB.3          // SW1 THIS WORKS AND TOGGLES THE BUZZER
Dim SW2 As PORTA.5          // SW2 input switch THIS MAKES NO DIFFERENCE AND DOES NOT TOGGLE THE BUZZER
Dim Buzzer As PORTA.4       // buzzer output
Dim SW1_Power As PORTA.2    // power the switches
Dim SW2_Power As PORTB.5    //

ANSELA = 0 // All Digital
ANSELB = 0
ANSELC = 0
ANSELD = 0
ANSELE = 0
TRISB.3 = 1
TRISA.5 = 1




// make SW1 and SW2 inputs
Input(SW1)
Input(SW2)

// main program...

High(SW1_Power)
High(SW2_Power)

Low(Buzzer)
Repeat
  While SW1 = 1 Or SW2 = 1     // ONLY SW1 makes the buzzer buzz
       Toggle (Buzzer)
       DelayUS (600)
  Wend
Low(Buzzer)
Until false
Beginner

bitfogav
Registered User
Registered User
Posts: 169
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Post by bitfogav » Wed Dec 28, 2011 4:43 pm

Sorry about the switch confusion. They are on/off switches not momentary push button switches.
I think I see where the problem is now I know how you've connected your switches, I changed the while loop with a If statement because thats where I thought one if your issues was, im sure if you changed the if statement back to the while loop, it will prob work with the SE version code I posted.

Code: Select all

While true 
  While SW1 = 1 Or SW2 = 1     // ONLY SW1 makes the buzzer buzz 
       Toggle (Buzzer) 
       DelayUS (600) 
  Wend 
    Low(Buzzer) 
Wend
Anyway im glad its all fixed now with the update :)

Post Reply