![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Hi all, My name is Patrick. This is my first time in this forum. I ve just bought a PIC 16F877. Wow, so exciting, and I wanted to build my own first application. Well, I dont know if it is feasible or not, because I am a newbie in this field! Ok, this is the specification: This timer is for marital arts, which allows me to select number of rounds, duration of round, and break time. Current time will be shown on a LCD. So I reckond, the max period of time should be around 5 mins. There are 3 buttons, which are stop, reset and start. I have few questions about this application. Could you please help me out? 1. There are many timers inside the chip such as TMR0,1,2,3 and even Watchdog timer. I dont know which one to use. If the max time is 5 mins, I think I can use Timer ) with 8 bit input. 2. I get an idea to use the crystal, but if so, I wont use teh CHIP I like make use of the chip. 3. How can I implement the button? Thanks Have a good day Patrick | |
| |
| | #2 |
|
Have a look at my tutorials, it should give you a few ideas. Timer1 is probably the best for your purposes, you can easily use it to generate regular interrupts which you count for your basic clock - for example, generate 1mS interrupts and count 1000 of them to increment the seconds counter. Interesting you are building a martial arts timer, which martial art do you do?, I'm a 2nd Dan in Ju Jitsu and a registered instructor and grading examiner. | |
| |
| | #3 |
|
easiest way to program a pic i find is in c you can download a trial version of the ccs compilier at www.ccsinfo.com you dont have to worry about memory locations. the code is ineffficent but a hell of alot easier | |
| |
| | #4 |
|
Hi, thanks for your replies. It will take me awhile to read the tutorials. But realy realy I found these tutorials so useful. Thanks again. :wink: I am abit more confident in high level programming language. I think this timer can be done by using C language, but honestly, I want to take this as a chance to learn more about assembly language. :shock: Well, I think this timer can be used in Karate, or Kick boxing. The max time would be 5 mins. It sounds so limitted, but I hope I can improve the timer when I get it done for basic functions. I am on holidays now, so full time working for ...PIC16f877 Thanks | |
| |
| | #5 |
|
Hi, I understand prescale of a timer. say timer counts from 256 to 0. If the prescale is 1:16 then the timer will generate an interrupt after 256*16 counts. How about postscale? is it important? Thanks | |
| |
| | #6 |
|
thanks
| |
| |
| | #7 | |
| Quote:
| ||
| |
| | #8 |
|
Thanks very much. Your site is so great. So basically, they are quite similar? I reckon it it possible to write this program with only prescale. Is it right? | |
| |
| | #9 | |
| Quote:
| ||
| |
| | #10 |
|
Hi, I left the Timer part for latter. I think it is easier to do the push button first. Here is my code: Code: title "ledon - Turn on a LED when a Button is Pressed"
include "D:/p16F877.inc"
__config (_CP_OFF & _PWRTE_ON & _HS_OSC & _WDT_ON & _BODEN_ON & _LVP_OFF & _DEBUG_ON)
errorlevel -302
;;;;;;;;Vectors ;;
org H'000'
goto MainLine
org H'004'
goto IntService
Stop
goto Stop
;;;Interrupt Service;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IntService
retfie
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;; Initial Subroutine;;;;
Initial
bcf STATUS,RP0 ;
bcf STATUS, RP1 ; Bank 0 selected
clrf PORTC
clrf PORTB
bsf STATUS,RP0 ; Bank 1 selected
movlw H'00' ; All pins of PORTC outputs
movwf TRISC
movlw H'11'
movwf TRISB ; All pins of PORTB inputs
bcf STATUS,RP0 ; Bank 0 selected
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MainLine
call Initial
MainLoop
btfsc PORTB,0 ; check Button 1, if it is not pushed, skip the next step
goto B1_routine
btfsc PORTB,1 ; check Button 2, if it is not pushed, skip the next step
goto B2_routine
goto TurnOff ; if bit 0 is 1, goto Turnoff
B1_routine
movlw b'10101010'
movwf PORTC
goto MainLoop
B2_routine
movlw b'01010101'
movwf PORTC
goto MainLoop
TurnOff
clrf PORTC
goto MainLoop
end
Button 1: shows 10101010 in port C Button 2: shows 01010101 in port C I wanted to test it in the MPLAB, but when I tried to force to change the PB0, PB1, the MPLab does not allow (test by stepping). Then I tried to change the config of portB, make them as outputs (I know, this is not correct, and the buttons are attached here!!!) (TRISB with all pins of 0), then MPLAB allows me to change its bits. This is so strange!!!! Anyone please help me. I reckon we can force the bits of INPUT port when stepping in MPLAB(simulation). Thanks | |
| |
| | #11 |
|
One more thing, this program seems I am polling to check the buttons. Is it good? I reckon I should make the button to generate an interrupt by itself. Can you give me some hints of how to do it? Thanks | |
| |
| | #12 | |
| Quote:
Code: movlw h'ff' movwf trisb
__________________ Falleaf mail@falleaf.net English forums at PIC Vietnam - Vietnamese Electronics forums R&P Trading and Forwarding Co. Ltd. Distributor of Microchip in Vietnam | ||
| |
| | #13 |
|
Oh thanks, Now I know, we cant use all pins in port B for I/O prupose. Thanks again | |
| |
| | #14 |
|
Can someone give me some hints for phush button with interrupts? Not polling ... Thanks | |
| |
| | #15 | |
| Quote:
| ||
| |
|
| Tags |
| pic, timer |
| Thread Tools | |
| Display Modes | |
| |