ck0210
- 17th August 2007, 09:32
Hi,
i am a colleage student and i am doing a pic project..
my project's concept is connecting a normal switch to the pic and let pic to count the time (in seconds) when the switch is switched on and display the results on LED until switched off...
EXAMPLE: when the switch is (switched on), pic starts to count the time from 0 second to xxx seconds. When the time is less than or equal to 5 seconds, it will blink the LED in portb.0. When the time is more than 5 seconds, it will blink the LED in portb.1. Then, when the swith is (switched off), the time counter will reset to 0 and wait for the next press on switch....
THIS IS MY CODE:
DEFINE osc 4 'using 4MHz oscillator
second VAR BYTE
TRISB.0= 0 ' define portb.0 as output
TRISB.1= 0 'define portb.1 as output
second= second + 1 'count from 0 second..1 second..2 seconds and so on..
start:
IF second <= 5 THEN
GOSUB loopa
ELSE
GOSUB loopb
PAUSE 500
ENDIF
loopa:
HIGH PORTB.0 'blinking led in portb.0
PAUSE 500
LOW PORTB.0
PAUSE 500
GOSUB loopa
loopb:
HIGH PORTB.1 'blinking led in portb.1
PAUSE 500
LOW PORTB.1
PAUSE 500
GOSUB loopb
RETURN 'return to start and count continuously until switch is switched off
END
But...my circuit cannot work..
i had read through picbasic Pro data sheet but i still dunno which part i did wrongly..
So..can anyone give me guidelines or tell me the errors in my project?
I will appreciate it...
Thanks a lot...
Eric 17/8/07
i am a colleage student and i am doing a pic project..
my project's concept is connecting a normal switch to the pic and let pic to count the time (in seconds) when the switch is switched on and display the results on LED until switched off...
EXAMPLE: when the switch is (switched on), pic starts to count the time from 0 second to xxx seconds. When the time is less than or equal to 5 seconds, it will blink the LED in portb.0. When the time is more than 5 seconds, it will blink the LED in portb.1. Then, when the swith is (switched off), the time counter will reset to 0 and wait for the next press on switch....
THIS IS MY CODE:
DEFINE osc 4 'using 4MHz oscillator
second VAR BYTE
TRISB.0= 0 ' define portb.0 as output
TRISB.1= 0 'define portb.1 as output
second= second + 1 'count from 0 second..1 second..2 seconds and so on..
start:
IF second <= 5 THEN
GOSUB loopa
ELSE
GOSUB loopb
PAUSE 500
ENDIF
loopa:
HIGH PORTB.0 'blinking led in portb.0
PAUSE 500
LOW PORTB.0
PAUSE 500
GOSUB loopa
loopb:
HIGH PORTB.1 'blinking led in portb.1
PAUSE 500
LOW PORTB.1
PAUSE 500
GOSUB loopb
RETURN 'return to start and count continuously until switch is switched off
END
But...my circuit cannot work..
i had read through picbasic Pro data sheet but i still dunno which part i did wrongly..
So..can anyone give me guidelines or tell me the errors in my project?
I will appreciate it...
Thanks a lot...
Eric 17/8/07