Re: There comes a time...
OK... so I'm onto the stage where I'm teaching myself how to program one of these microcontrollers. The learning curve is pretty steep so I've decided to break this part down into smaller projects that will help me get an idea of what's going on.
Project #1 - Make an LED flash with an accurate half-second delay
Project #2 - Brake light flasher. When the brake lever is pulled, flash the brake light ten times over four seconds before holding steady.
Project #3 - Initial stab at this ignition
Project one is well underway. I have my code done and I'm just waiting on the mail before my chips and programmer get here. I'll save you guys the code for projects two and three, but here's just a taste of what's necessary to get a single LED to flash with a half second delay:
;=-=-=-=-=-= SETUP THE CONSTANTS =-=-=-=-=-=
STATUS equ 03h ;address of the STATUS register
TRISA equ 85h ;address of the tristate register for port A
PORTA equ 05h ;address of Port A
COUNT1 equ 0Ch ;first counter for our delay loop, address to 0Cx0
COUNT2 equ 0Dh ;second counter for our delay loop, address to 0Dx0
COUNT3 equ 0Eh ;third counter for delay loop, address to 0Ex0
org 0h ;start program section
;=-=-=-=-=-= SETUP THE PORT =-=-=-=-=-=
MAIN clrwdt
bsf STATUS,5 ;switch to bank 1
movlw 0h ;set port A
movwf TRISA ;to output
bcf STATUS,5 ;back to bank 0
movlw 02h ;turn on LED by first putting it into the W register
movwf PORTA ;and then onto the port
;=-=-=-=-=-= FLIP LED AND THEN DELAY =-=-=-=-=-=
START xorwf PORTA,1 ;flip PORTA from on to off or off to on depending on current status
call DELAY ;delay for half a second
;=-=-=-=-=-= RESTART PROGRAM =-=-=-=-=-=
goto START
;=-=-=-=-=-= SUBROUTINES =-=-=-=-=-=
DELAY
movlw 0x03
movwf COUNT1
movlw 0x18
movwf COUNT2
movlw 0x02
movwf COUNT3
Delay_0
decfsz COUNT1, f
goto $+2
decfsz COUNT2, f
goto $+2
decfsz COUNT3, f
goto Delay_0
;6 cycles
goto $+1
goto $+1
goto $+1
return ;end DELAY
end ;end PROGRAM
OK... so I'm onto the stage where I'm teaching myself how to program one of these microcontrollers. The learning curve is pretty steep so I've decided to break this part down into smaller projects that will help me get an idea of what's going on.
Project #1 - Make an LED flash with an accurate half-second delay
Project #2 - Brake light flasher. When the brake lever is pulled, flash the brake light ten times over four seconds before holding steady.
Project #3 - Initial stab at this ignition
Project one is well underway. I have my code done and I'm just waiting on the mail before my chips and programmer get here. I'll save you guys the code for projects two and three, but here's just a taste of what's necessary to get a single LED to flash with a half second delay:
;=-=-=-=-=-= SETUP THE CONSTANTS =-=-=-=-=-=
STATUS equ 03h ;address of the STATUS register
TRISA equ 85h ;address of the tristate register for port A
PORTA equ 05h ;address of Port A
COUNT1 equ 0Ch ;first counter for our delay loop, address to 0Cx0
COUNT2 equ 0Dh ;second counter for our delay loop, address to 0Dx0
COUNT3 equ 0Eh ;third counter for delay loop, address to 0Ex0
org 0h ;start program section
;=-=-=-=-=-= SETUP THE PORT =-=-=-=-=-=
MAIN clrwdt
bsf STATUS,5 ;switch to bank 1
movlw 0h ;set port A
movwf TRISA ;to output
bcf STATUS,5 ;back to bank 0
movlw 02h ;turn on LED by first putting it into the W register
movwf PORTA ;and then onto the port
;=-=-=-=-=-= FLIP LED AND THEN DELAY =-=-=-=-=-=
START xorwf PORTA,1 ;flip PORTA from on to off or off to on depending on current status
call DELAY ;delay for half a second
;=-=-=-=-=-= RESTART PROGRAM =-=-=-=-=-=
goto START
;=-=-=-=-=-= SUBROUTINES =-=-=-=-=-=
DELAY
movlw 0x03
movwf COUNT1
movlw 0x18
movwf COUNT2
movlw 0x02
movwf COUNT3
Delay_0
decfsz COUNT1, f
goto $+2
decfsz COUNT2, f
goto $+2
decfsz COUNT3, f
goto Delay_0
;6 cycles
goto $+1
goto $+1
goto $+1
return ;end DELAY
end ;end PROGRAM