I'm using a pic 16f628a.
It's been a while since i've done pic programming and it's taking time to get back into it....
Basically the circuit has four LEDs and four press buttons.
RA4,RA5,RA6,RA7 are press buttons
RB0,RB1,RB2,RB3 are LEDs
All I want to do is have the corresponding LED to come on for 255 mSeconds when the button is pressed and then switch off.
So for example, if RA4 is pressed, I would like RB0 LED to come on, RA5 switches on RB1, RA6 to switch on RB2 and finally RA7 to bring on RB3.
I do get alot of warnings but not errors when I try to build this project... Something about OpCode.
Thanks!
It's been a while since i've done pic programming and it's taking time to get back into it....
Basically the circuit has four LEDs and four press buttons.
RA4,RA5,RA6,RA7 are press buttons
RB0,RB1,RB2,RB3 are LEDs
All I want to do is have the corresponding LED to come on for 255 mSeconds when the button is pressed and then switch off.
So for example, if RA4 is pressed, I would like RB0 LED to come on, RA5 switches on RB1, RA6 to switch on RB2 and finally RA7 to bring on RB3.
Rich (BB code):
LIST p=16F628 ; TELLS THE PROGRAMMER WHAT CHIP WE'RE USING.
include "P16F628.inc" ; INCLUDES DEFAULTS FOR THE CHIP.
ERRORLEVEL 0, -302 ;suppress bank selection messages
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)
;__config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_OFF
cblock 0x20 ;start of general purpose registers
count ;used in looping routines
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
endc
; **************************************
; LEDs and Switches
LEDPORT Equ PORTB ;set constant LEDPORT = 'PORTB'
SWPORT Equ PORTA ;set constant SWPORT = 'PORTB'
LEDTRIS Equ TRISB
SWTRIS Equ TRISA
SW1 Equ 0x04 ; Identifies Switch One on Schematic diagram
SW2 Equ 0x05 ; Identifies Switch Two on Schematic diagram
SW3 Equ 0x06 ; Identifies Switch Three on Schematic diagram
SW4 Equ 0x07 ; Identifies Switch Four on Schematic diagram
LED1 Equ 0x00 ; Identifies LED One on the Schematic diagram
LED2 Equ 0x01 ; Identifies LED Two on the Schematic diagram
LED3 Equ 0x02 ; Identifies LED Three on the Schematic diagram
LED4 Equ 0x03 ; Identifies LED Four on the Schematic diagram
SWDel Set Delay50 ;set the de-bounce delay (has to use 'Set' and not 'Equ')
; **************************************
; end of LEDs and switches
org 0x0000 ;org sets the origin, 0x0000 for the 16F628
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)
SetPorts bsf STATUS, RP0 ;select bank 1
movlw 0x00 ; make all pins outputs
;bcf STATUS, RP0 ;select bank 0
movlw b'00001111'
;movlw 0x00 ; make all pins outputs
movwf LEDTRIS
bcf STATUS, RP0 ;select bank 0
clrf LEDPORT ;set all outputs low
;clrf SWPORT
; Loop waits for a button press.
Loop1 btfss SWPORT, SW1 ; Increase time button
call Switch1 ; Call sub routine when SW1 is pressed
btfss SWPORT, SW2 ; Reset time button
call Switch2 ; Call sub routine when SW2 is pressed
btfss SWPORT, SW3 ; Start Timer button
call Switch3
Goto Loop1
Switch1 call SWDel
bsf LEDPORT, LED1 ;turn LED1 on
call Delay255
bcf LEDPORT,LED1
goto Loop1
Switch2 call SWDel
bsf LEDPORT, LED2 ;turn LED1 on
call Delay255
bcf LEDPORT, LED2
goto Loop1
Switch3 Call SWDel
bsf LEDPORT, LED3 ;turn LED1 on
call Delay255
bcf LEDPORT,LED3
goto Loop1
; ***************************************
; DELAY ROUTINES
Delay255 movlw 0xff ;delay 255 mS (0xff in hexadecimal)
goto d0
Delay100 movlw d'100' ;delay 100mS
goto d0
Delay50 movlw d'50' ;delay 50mS
goto d0
Delay20 movlw d'20' ;delay 20mS
goto d0
Delay5 movlw 0x05 ;delay 5.000 ms (4 MHz clock)
d0 movwf count1
d1 movlw 0xC7 ;delay 1mS
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
; END OF DELAY ROUTINES
; ***************************************
end
Thanks!