PDA

View Full Version : Blinking LED's & Binary Counter w/ PIC [Project]


Mr. Hasselhoff
04-28-2009, 09:33 AM
So I'm taking EE 186, which is non-required and only 1 credit. There are 5 structured labs and then you pick any project, and work on it. Originally my partner and I decided to do a guitar hero bot, but with the deadline coming up, and finals right around the corner, I didn't have time to debug some problems in my code.

Instead I decided to do a PIC-based alternating LED project. Basically I programmed a 16F960 PIC to flash the LED's consecutively, and back and forth. I programmed the PIC myself, and created, and soldered my board together all by myself. I know this stuff isn't hard, but being a freshman electrical engineer, we haven't had any theory courses so I thought this was a cool experience, considering I did this completely on my own, and did not follow any tutorials or guides. I know it's nothing incredibly complex, but I'm still damn proud of it since like I said, I did this all on my own.

The program I wrote is all in assembly. Since I have the hardware down, I'm going to see if I can make a binary clock for this hardware implementation as my project instead, but I'm not sure how feasible that is because this project is due this Thursday. Funny thing that I put it off completely until yesterday, and did everything last night.


Here's a pic, keep in mind most of the wiring is hidden on the underside, so there's a lot more to it than what you see from the top.


http://i42.tinypic.com/15i6e5c.jpg

And here is the code if anybody is interested

#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)

cblock 0x20
Delay1
Delay2
Display
endc

org 0
Start:
bsf STATUS,RP0
clrf TRISC
bcf STATUS,RP0
movlw 0x08
movwf Display
MainLoop:
movf Display,w
movwf PORTC
OndelayLoop:
decfsz Delay1,f
goto OndelayLoop
decfsz Delay2,f
goto OndelayLoop

bcf STATUS,C
rrf Display,f
btfsc STATUS,C
bsf Display,3
goto MainLoop
end


Edit:
Woot, I wrote the code for the binary clock! Awesome, I'll post the source later.

Mr. Hasselhoff
04-29-2009, 10:47 AM
Here is the code for the binary counter, if someone needs an explanation of how it works, let me know.

Once again, this is for the 16F690.


list p=16F690
#include <p16F690.inc>
org 2007h
dw _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF


count1 equ 20h
count2 equ 21h
count3 equ 22h

org 00h
goto startProgram
org 04h
goto isRoutine

startProgram
movlw 00h
banksel TRISC
movwf TRISC
banksel PORTC
movwf PORTC
movwf count3
back3 movlw .250
call delay
incf count3
movfw count3
movwf PORTC
goto back3

isRoutine

retfie

delay movwf count2
back2 movlw .248
movwf count1
back decf count1
btfss STATUS,Z
goto back

decf count2,F
btfss STATUS,Z
goto back2
return

end