TS-lycos-D81

Tom Swan Says:

Hello world,

I have just started PIC programming (16F84). I decided to make it a little hoby as I find the whole concept quite interesting. I started working through an old college tutorial book I managed to find. I was really enjoying myself until I discovered the following two questions:

Q1.

For the following programs assume that the hardware has the following configuration:

a) Operating from an RC oscillator with values of R = 10K , C =100pF .
b) A red LED is connected to RA0 in common anode configuration.
c) A switch is connected to RB0 (normally high).


Program 1 – Watchdog timer

Write a program to flash the LED on and off after the switch connected to RB0 has been pressed. If the switch connected to RB0 is pressed for a second time the LED should turn off. You may use polling to test for a switch press. The LED should flash on and off at a frequency of 7hz. Use the watchdog timer to provide the time delay and make use of the powerdown mode (SLEEP) during the delay. Document program, include clear explanations and show all calculations.

My solution:

status equ 0x03
trisa equ 0x05
porta equ 0x05
trisb equ 0x06
portb equ 0x06
opt equ 0x01
value equ 0x0c
org 0x00
clrwdt
bsf status,5
movlw 0xff
movwf trisb
movlw 0x00
movwf trisa
bcf opt,7
bsf opt,3
bcf opt,2
bsf opt,1
bcf opt,0
bcf status,5
movlw 0xff
movwf porta
movlw 0x01
movwf value
wait clrwdt
btfsc portb,0
goto wait
relax sleep

movlw 0x01
xorwf value,f
movf value,w

movwf porta
goto relax
end

Q2

Write a program to carry out the same function as above but use the timer to produce the required delay. Use the interrupt source on RB0 to detect a switch press and use the timer overflow interrupt to determine the timer time out. Use the RB0 interrupt to wake the device up from sleep before the first switch press. Use the RB0 interrupt to stop and clear the flashing LED after the second switch press. The sleep function cannot be used whilst the LED is flashing on and off.
Document program, include clear explanations and show all calculations.

OK, now to be honest I spent about a week on the first program! I am not sure if it even works as I have not introduced it to bread board yet. My major malfunction is the second question, I just don't know where to start and can't seem to find any basic examples of code with which I can visualise the operation of the interupt routine.

If anyone could shed any light on how my code should look or where I could find explanations with examples on the web I would be forever grateful. (tomswanuk@lycos.co.uk)

Regards, Tom.