Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 29th April 2009, 01:59 AM   #16
Default

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:
Standards are wonderful. That's why there are so many of them.
Soundguy is offline  
Old 29th April 2009, 03:02 AM   #17
Default

Quote:
Originally Posted by Soundguy View Post
Hi again, MR. RB
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?
Yep, leave freerunning TMR1 for the 5 sec system. The TMR0 you can trash for general use, ie clr it then use for simple delays up to 256 uS etc.

Quote:
Originally Posted by Soundguy View Post
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.
Yeah I got what you did, its a sensible system. To get the single value, you could just add 10 to that value, for each count in the 10's digit.

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:
Originally Posted by Soundguy View Post
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.
Sounds nice and professional.


Quote:
Originally Posted by Soundguy View Post
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.
Cool I get it. To fill the screen with * should take less than 1mS to write those 30 or so chars. That would just be an immediate task on receipt of the first keypress.

Cheers.

Last edited by Mr RB; 29th April 2009 at 03:04 AM.
Mr RB is offline  
Old 29th April 2009, 10:02 PM   #18
Default

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"
That's a "blocking" subroutine which probably wouldn't do you much good but if you put it inside a 5 second timeout routine then it might do what you want.

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
;
A GetKey subroutine with 5 second timeout should make your main program a lot simpler. Just insert your LCD strings as required.

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
.......
Good luck with your project.

Regards, Mike

Last edited by Mike, K8LH; 1st May 2009 at 02:18 PM.
Mike, K8LH is offline  
Old 30th April 2009, 04:26 AM   #19
Talking

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:
Standards are wonderful. That's why there are so many of them.
Soundguy is offline  
Reply

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



All times are GMT. The time now is 02:32 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker