Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need Some Help

Status
Not open for further replies.

Overclocked

Member
Code Doesnt Work

I just Got my junebug together and the programming function works, since I used the test code from BRE. Basically, I want to press a button and have the LED Light.

Code is from Swordfish Basic. Code Complies, but the actual hardware doesnt work.

Device = 18F1320
Clock = 4 // 4MHz clock
OSCCON = $62 // select 4MHz internal clock
End //Complier gives and Error if I dont have this
Output RA.0
Output RA.6
Input RB.0

Dim RB0 As Bit //Switch 1
Dim A0 As Bit //LED A0
Dim A6 As Bit //LED A0 Control

If RB0 = 0 Then
A0 = High
A6 = Low
End
 
Last edited:
I don't know where you got that code cause it doesn't work.

Try,
Code:
Device = 18F1320
Clock = 4 // 4MHz clock

Config OSC = INTIO2, WDT = OFF, LVP = OFF

OSCCON = $62        // select 4MHz internal clock
ADCON1  = $7f       //all digital
INTCON2.7=0         //turn on WPUs
While true
    If (PORTB.0=0) Then //if button 1 pressed
        TRISA.7 = 1     //light LED 1
        High(PORTA.0)
        Low (PORTA.6) 
     Else
        TRISA.7 = 1     //light LED 2
        Low (PORTA.0)
        High(PORTA.6)      
    EndIf 
Wend

End

Mike.
 
I don't know where you got that code cause it doesn't work.

Try,
Code:
Device = 18F1320
Clock = 4 // 4MHz clock

Config OSC = INTIO2, WDT = OFF, LVP = OFF

OSCCON = $62        // select 4MHz internal clock
ADCON1  = $7f       //all digital
INTCON2.7=0         //turn on WPUs
While true
    If (PORTB.0=0) Then //if button 1 pressed
        TRISA.7 = 1     //light LED 1
        High(PORTA.0)
        Low (PORTA.6) 
     Else
        TRISA.7 = 1     //light LED 2
        Low (PORTA.0)
        High(PORTA.6)      
    EndIf 
Wend

End

Mike.

I made it Up, err well tried anyway. I'll try your code in the morning, thanks.
 
You may want to download the **broken link removed**file from Bill's site. It has 2 functions defined, one that lights an LED and another that reads the push buttons.

If you download it then have a play with this,
Code:
Device = 18F1320
Clock = 4 // 4MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF

Include "JuneBug.bas"

Dim Lit As Byte
Dim Keys As Byte

OSCCON = $62            // select 4MHz internal clock
ADCON1  = $7f           //all digital
Lit=1
While true
    DelayMS(10)         //for debounce
    Keys=ReadKeys()     //read the push buttons
    If (Keys=1) Then    //if button 1 pressed
        Lit=Lit+1       //light LED to right
        If Lit=7 Then   //gone to far
            Lit=1       //yes, so wrap around
        EndIf
    ElseIf (Keys=2) Then
        Lit=Lit-1       //scroll em left
        If Lit=0 Then 
            Lit=6
        EndIf
    EndIf 
    LED(Lit)            //light the LED
Wend

End
Then you can have fun trying to get it doing other things.


Mike.
 
I don't know where you got that code cause it doesn't work.

Try,
Code:
Device = 18F1320
Clock = 4 // 4MHz clock

Config OSC = INTIO2, WDT = OFF, LVP = OFF

OSCCON = $62        // select 4MHz internal clock
ADCON1  = $7f       //all digital
INTCON2.7=0         //turn on WPUs
While true
    If (PORTB.0=0) Then //if button 1 pressed
        TRISA.7 = 1     //light LED 1
        High(PORTA.0)
        Low (PORTA.6) 
     Else
        TRISA.7 = 1     //light LED 2
        Low (PORTA.0)
        High(PORTA.6)      
    EndIf 
Wend

End

Mike.

One Question, Why are you setting Port 7 to a Input (TRISA.7 = 1)?
 
One Question, Why are you setting Port 7 to a Input (TRISA.7 = 1)?

It's because I copied it from the Junebug.bas module. You need to set A7 to input to make sure that none of the other LEDs light. It's not needed in this example as the default is for all pins to be input.

Try setting it to output and working out why it does what it does.

Mike.
 
The large program at the end of the Junebug manual was written by David Baker of Swordfish. The nice thing is since the only limitation on the SE (free) edition is 256 bytes of RAM it matches perfectly the 18F1320 RAM.

The JPUG issues and Swordfish forums / wiki are well worth reading. I've got to get back to doing those issues.
 
It's because I copied it from the Junebug.bas module. You need to set A7 to input to make sure that none of the other LEDs light. It's not needed in this example as the default is for all pins to be input.

Try setting it to output and working out why it does what it does.

Mike.

Ah, I see. If trisA.7= 0 Then it is set as an output and Lights up Some LEDs when set to low. If I put PortA.7 Set to High, I light up other LEDS (A6 and A7 when not pressed, A0 and A2 when pressed). I see what I did wrong in my original program, I tried Using variables that had no connections to the hardware, and I didnt set up the pull ups in the PIC.

The large program at the end of the Junebug manual was written by David Baker of Swordfish. The nice thing is since the only limitation on the SE (free) edition is 256 bytes of RAM it matches perfectly the 18F1320 RAM.

The JPUG issues and Swordfish forums / wiki are well worth reading. I've got to get back to doing those issues.

I was under the impression that swordfish was limited to the amount of Ram In the device itself, unless Im wrong.
 
The PIC has weak pullups built into PORTB, you simply need to clear the RBPU bit.

No it'll only compile if you've used less than 256 bytes or RAM regardless of the PIC.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top