Okay so this is my first day getting to use a microcontroller, and I am well and truly stuck. I'm using a PIC18F2550 and am trying to follow this tutorial Tutorial 2 - “Hello World” Program in Assembly Language PIC18F.COM - Tutorials and Sample Code (although the tutorial is written for the PIC18F4550).
So far my code looks like this:
When I run the program, the LED just goes on and stays on instead of blinking. By switching the line
with
I am able to turn the light off, and with
I am able to turn the light on.
However when I run two BTG instructions right after one another the bit does not toggle the second time the BTG is executed, which makes me think there's something wrong with the toggle??? Any ideas?
Thanks
So far my code looks like this:
Code:
#include<P18F2550.inc>
CONFIG WDT=OFF; disable watchdog timer
CONFIG MCLRE = ON; MCLEAR Pin on
CONFIG DEBUG = ON; Enable Debug Mode
CONFIG LVP = OFF; Low-Voltage programming disabled (necessary for debugging)
CONFIG FOSC = INTOSCIO_EC;Internal oscillator, port function on RA6
org 0; start code at 0
Delay1 res 1 ;reserve 1 byte for the variable Delay1
Delay2 res 1 ;reserve 1 byte for the variable Delay2
Start:
CLRF PORTA ; Initialize PORTA by
; clearing output
; data latches
CLRF LATA ; Alternate method
; to clear output
; data latches
CLRF TRISA
CLRF Delay1
CLRF Delay2
MainLoop:
BTG PORTA,RA5 ;Toggle (20)
Delay:
DECFSZ Delay1,1 ;Decrement Delay1 by 1, skip next instruction if Delay1 is 0
GOTO Delay
DECFSZ Delay2,1
GOTO Delay
GOTO MainLoop
end
When I run the program, the LED just goes on and stays on instead of blinking. By switching the line
Code:
BTG PORTA,RA5 ;Toggle
with
Code:
BCF PORTA,RA5 ;Toggle
Code:
BCF PORTA,RA5 ;Toggle bit
However when I run two BTG instructions right after one another the bit does not toggle the second time the BTG is executed, which makes me think there's something wrong with the toggle??? Any ideas?
Thanks