![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #16 | |
|
Hi again, MR. RB Thank you for your input regarding the timer setups. Just to make sure that I understand, are you suggesting that I use timer0 for a system tick, for general use, and timer 1 for special items such as the 5 second countdown? If, so, I think that I can handle that and will try it tomorrow. In response to your question about multiplying the 2nd digit, the idea was to add up the numbers created by the keypad decoding and end up with a number that would translate directly to the relay number that I want to activate. I originally wrote some code that simply incremented a register form 0-40, and output the appropriate code to work with the 5 X 8 matrix arrangement for the relays and output indicating LED's as a test. The LED's are in parallel with the relays in the prtotype. When I first started designing this project, I built a circuit board with 40 LED's arranged in a 5 X 8 matrix in order to control all of them with a single port, including a seperate enable line, which is used to turn the selected output on for whatever length of time you want, as well as intoducing a cadence to the output, if needed, such as duplicating a telephone ring signal, be it either North American or European style ring cycles. This is the method I have used in the prtototype for controlling the relays. I was trying to write the code so that it would be useable in future projects. Lastly, the message displayed in the LCD after the 1st keypress is really just a screen full of asterisks with a space in the middle of the bottom line where the entered digits go. This is based on a display used by a prominent manufacturer of similar type "user friendly" entry panels that I have seen. After the 3 keypad digits have been entered, the display just shows "CALLING" whilst the relay is activated.That is the last message displayed in the whole sequence of events. After that, the system resets and reverts to the welcoming message. I will let you know how I make out with the new coding. Cheers, Soundguy.
__________________ Quote:
| ||
| |
| | #17 | ||||
| Quote:
Quote:
Personally I would have kept the data entry/display tasks immediate and as simplified as possible, with the relay decoding all done at the end in the relay driver code. Quote:
Quote:
Cheers. Last edited by Mr RB; 29th April 2009 at 03:04 AM. | |||||
| |
| | #18 |
|
Soundguy, Forgive me for butting in but I wonder if you couldn't just poll the keypad encoder chip? For example, assuming the 'keypressed' line on RB4 and the four data bits on RB3..RB0, there should be plenty of time in your application to sample the switches without ever missing a new key press. Code: sample
movf PORTB,W ; |B0
andlw b'00011111' ; mask off unused bits |B0
xorwf swlatch,W ; changes? |B0
bz GetLp ; no, branch, else |B0
xorwf swlatch,F ; update switch state latch |B0
btfss swlatch,4 ; new release? no, skip, else |B0
goto sample ; branch, try again |B0
call beep ; send new press beep |B0
movf swlatch,W ; get data again |B0
andlw 0x0F ; mask off unused bits |B0
addwf PCL,F ; return key value |B0
dt "0123456789ABCDEF"
Code: ;
; get key with 5 second time-out
;
GetKey
movlw 5 ; timeout = 5.000 seconds |B0
movwf secs ; |B0
clrf msecslo ; |B0
clrf msecshi ; |B0
GetLp DelayCy(1*msecs-23) ; sample at 1 msec intervals |B0
movlw d'99' ; reset value for 'msecslo' |B0
decf msecslo,F ; dec msecs lo |B0
btfsc msecslo,7 ; negative? no, skip, else |B0
decf msecshi,F ; dec msecs hi |B0
btfsc msecslo,7 ; negative? no, skip, else |B0
movwf msecslo ; reset msecslo = 100 |B0
movlw d'9' ; reset value for 'msecshi' |B0
btfsc msecshi,7 ; negative? no, skip, else |B0
decf secs,F ; dec seconds counter |B0
btfsc msecshi,7 ; negative? no, skip, else |B0
movwf msecshi ; reset msecshi = 10 |B0
setc ; preset timeout indicator |B0
movf secs,W ; |B0
iorwf msecslo,W ; |B0
iorwf msecshi,W ; timer timed out? |B0
skpnz ; no, skip, else |B0
return ; return W = 0 and C = 1 |B0
movf PORTB,W ; |B0
andlw b'00011111' ; mask off unused bits |B0
xorwf swlatch,W ; changes? |B0
bz GetLp ; no, branch, else |B0
xorwf swlatch,F ; update switch state latch |B0
btfss swlatch,4 ; new press? yes, skip, else |B0
goto GetLp ; branch, ignore 'new release' |B0
call beep ; send new press beep |B0
movf swlatch,W ; get data again |B0
andlw 0x0F ; mask off unused bits |B0
addwf PCL,F ; return W = key and C = 0 |B0
dt "0123456789ABCDEF"
;
; beep
;
beep
bsf beepctr,4 ; task 32 msec "beep" |B0
toggle movf PORTA,W ; |B0
xorlw 1<<spkr ; toggle spkr bit |B0
movwf PORTA ; toggle spkr pin |B0
DelayCy(1*msecs-6) ; interval for 500 Hz tone |B0
decfsz beepctr,F ; done? yes, skip, else |B0
goto toggle ; toggle spkr again |B0
return ; |B0
;
Code: Loop
PutLCD (cmd,clearscreen); |B0
PutSTR "Welcome"
PutLCD (cmd,line2+0) ; line 2, htab 0 |B0
PutSTR "Resident code? "
Digit1 call GetKey ; get key (5 second timeout) |B0
bc Digit1 ; branch if timeout |B0
xorlw '0' ; is it '0'? |B0
bnz Digit1 ; no, branch, else |B0
movlw '0' ; |B0
call PutDat ; print the '0' |B0
Digit2 call GetKey ; get key (5 second timeout) |B0
bc Loop ; branch if timeout |B0
movwf tens ; save key, '0'..'9' |B0
sublw '3' ; '0'..'3' range? |B0
bnc Digit2 ; no, branch, else |B0
movf tens,W ; |B0
call PutDat ; print to LCD |B0
Digit3 call GetKey ; get key (5 second timeout) |B0
bc Loop ; branch if timeout |B0
.......
Regards, Mike Last edited by Mike, K8LH; 1st May 2009 at 02:18 PM. | |
| |
| | #19 | |
|
Thanks for the input, Mike. I am going to poll the keypad decoder now, instead of using it for an interrupt. I intend tp poll it during a TMRO interrupt period, based on what MR.RB suggested. I like his idea of using the TMRO for a system "tick", and using the TMR1 for any other timing issues that I need to deal with. I will look carefully at the code you provided, as I think that it will be usefull. BEEBOP has also been very helpful. I am not uncomfortable with PIC's and assembly language, but I know that I still have a lot to learn. The timer modules and such are items that I have not utilized yet, as I am having trouble getting my head around some of the concepts. I really appreciate everybody's help and input on this project, and hope to be able to contribute, myself in the future to this forum as well as the other forums on this site. I welcome any and all comments on this project, as I think that if I hit myself in the head with all of this information, it is bound to sink in. ![]() When it is all done, I'll post the results. Regards, Soundguy
__________________ Quote:
| ||
| |
|
| Tags |
| pic, question, timer |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Timer for PIC 16F877 MictroController | pal | Micro Controllers | 1 | 5th November 2005 06:56 PM |
| timer on 16f877 | goodpickles | Micro Controllers | 1 | 18th March 2005 08:59 AM |
| Question about the 555 timer | xenoxion | General Electronics Chat | 4 | 22nd June 2004 09:55 PM |
| 16F877 question | TKS | Micro Controllers | 7 | 26th May 2004 11:46 AM |
| PIC 16F877 timer | patricktran | Micro Controllers | 31 | 6th May 2004 02:05 PM |