Use the row column method. Get a keypad that is setup as rows and
columns (not indivual switches) Then hook the rows up to a couple ports pins
setup as outputs of your uC and hook the columns up to a couple port pins setup
as inputs. Now one by one power one row then check all the columns until
you see a "high" and you have your key.. don't forget to
put in either a debounce delay or whatever debounce method you want to
use.
I have code but it's sort of long, probably could be
optimized, I am not the best programmer.
Chas
|
Microchip Music example
This one works....thanks very much. Now I have some examples
to study starting with Microchip's original code and your modifications.
Now lets see if I can learn something from these! I might be asking some
questions later.
Thanks again for your help.
Regards,
Stephen D. Barnes
|
|
Hi all, I have a little A/D program that gives me some results from an analog sensor the problem is I get some strange values every so often. For example If the sensor is reading a 124 an occasional lower number seems to pop up. Any ideas of what this could be? Here's my code so you get an idea of what I'm doing. Thanks Aaron CODE::::
radix hex TEMP equ 0x0e
main call InitAD Update bsf ADCON0,GO loop return
end
|
It would appear that the code at 'Loop' is incorrect. More commonly it looks like: bsf ADCON0,GO Loop: btfsc ADCON0,GO goto Loop goto Update ?what does the 'return' do? --- In , Aaron Morris <aaron_morris_2000@y...> wrote: > > Hi all, > > I have a little A/D program that gives me some results from an analog sensor the problem is I get some strange values every so often. For example If the sensor is reading a 124 an occasional lower number seems to pop up. Any ideas of what this could be? Here's my code so you get an idea of what I'm doing. > > Thanks > > Aaron > > CODE:::: > list pf877 > ERRORLEVEL -302 > #include "P16F877.INC" > > radix hex > > TEMP equ 0x0e > TEMP2 equ 0x0f > org 0x000 > start > movlw 0x00 > movwf PORTB > bsf STATUS, RP0 > clrf TRISB > movlw 0x00 > movwf TRISB > bcf STATUS, RP0 > clrf PORTB > > main > > call InitAD > > Update > movf ADRESH,w > movwf PORTB > call SetupDelay > > bsf ADCON0,GO > > loop > btfsc ADCON0,GO > goto Update > > goto loop > > return > SetupDelay > movlw 0x05 > movwf TEMP > SD > decfsz TEMP,f > goto SD > return > InitAD > bsf STATUS, 5 > movlw b'00001110' > movwf ADCON1 > bcf STATUS, 5 > movlw b'11000001' > movwf ADCON0 > clrf ADRESL > clrf ADRESH > clrf PORTB > return > > end > > --------------------------------- > |
How do you know if its a real 124 ? You are using only the first most semnificative byte from adresh, and the result is left justified, so you have lost the last two bits in adresl. Check if your delay have indeed the required aquisition time of 20uS. top 10 wishes, Vasile http://surducan.netfirms.com On Tue, 15 Jul 2003, Aaron Morris wrote: > > Hi all, > > I have a little A/D program that gives me some results from an analog sensor the problem is I get some strange values every so often. For example If the sensor is reading a 124 an occasional lower number seems to pop up. Any ideas of what this could be? Here's my code so you get an idea of what I'm doing. > > Thanks > > Aaron > > CODE:::: > list pf877 > ERRORLEVEL -302 > #include "P16F877.INC" > > radix hex > > TEMP equ 0x0e > TEMP2 equ 0x0f > org 0x000 > start > movlw 0x00 > movwf PORTB > bsf STATUS, RP0 > clrf TRISB > movlw 0x00 > movwf TRISB > bcf STATUS, RP0 > clrf PORTB > > main > > call InitAD > > Update > movf ADRESH,w > movwf PORTB > call SetupDelay > > bsf ADCON0,GO > > loop > btfsc ADCON0,GO > goto Update > > goto loop > > return > SetupDelay > movlw 0x05 > movwf TEMP > SD > decfsz TEMP,f > goto SD > return > InitAD > bsf STATUS, 5 > movlw b'00001110' > movwf ADCON1 > bcf STATUS, 5 > movlw b'11000001' > movwf ADCON0 > clrf ADRESL > clrf ADRESH > clrf PORTB > return > > end > > --------------------------------- > |
|
Vasile,
You are probably right as I am only reading ADRESH. Do I have to Add
both ADRESH + ADRESL to get the correct value. I'm not sure how both
of these registers work. Any information you know on this subject is
greatly welcomed.
Thanks for your help
Aaron
Vasile Surducan <v...@s3.itim-cj.ro> wrote:
|
The A/D converter is 10 bits wide - with left justification the upper 8 bits are in ADRESH and the lower 2 bits in the upper 2 bits of ADRESL. With right justification the upper 2 bits of the result are in the lower 2 bits of ADRESH and the lower 8 bits are in ADRESL. Left justification, as you have it, is quite popular if you only need to resolve 1 part in 256. No problem with dumping the lower 2 bits unless you want to resolve 1 part in 1024. --- In , Aaron Morris <aaron_morris_2000@y...> wrote: > Vasile, > > You are probably right as I am only reading ADRESH. Do I have to Add both ADRESH + ADRESL to get the correct value. I'm not sure how both of these registers work. Any information you know on this subject is greatly welcomed. > > Thanks for your help > Aaron > Vasile Surducan <vasile@s...> wrote: > How do you know if its a real 124 ? You are using only the first most > semnificative byte from adresh, and the result is left justified, so you > have lost the last two bits in adresl. Check if your delay have indeed > the required aquisition time of 20uS. > > top 10 wishes, > Vasile > http://surducan.netfirms.com > On Tue, 15 Jul 2003, Aaron Morris wrote: > > > > > Hi all, > > > > I have a little A/D program that gives me some results from an analog sensor the problem is I get some strange values every so often. For example If the sensor is reading a 124 an occasional lower number seems to pop up. Any ideas of what this could be? Here's my code so you get an idea of what I'm doing. > > > > Thanks > > > > Aaron > > > > CODE:::: > > > > > > list pf877 > > ERRORLEVEL -302 > > #include "P16F877.INC" > > > > radix hex > > > > TEMP equ 0x0e > > TEMP2 equ 0x0f > > > > > > org 0x000 > > start > > movlw 0x00 > > movwf PORTB > > bsf STATUS, RP0 > > clrf TRISB > > movlw 0x00 > > movwf TRISB > > bcf STATUS, RP0 > > clrf PORTB > > > > main > > > > call InitAD > > > > Update > > movf ADRESH,w > > movwf PORTB > > call SetupDelay > > > > bsf ADCON0,GO > > > > loop > > btfsc ADCON0,GO > > goto Update > > > > goto loop > > > > return > > > > > > SetupDelay > > movlw 0x05 > > movwf TEMP > > SD > > decfsz TEMP,f > > goto SD > > return > > > > > > InitAD > > bsf STATUS, 5 > > movlw b'00001110' > > movwf ADCON1 > > bcf STATUS, 5 > > movlw b'11000001' > > movwf ADCON0 > > clrf ADRESL > > clrf ADRESH > > clrf PORTB > > return > > > > end > > > > > > > > > > > > > > > > > > > > > > > > > > --------------------------------- > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the instructions > > ">http://docs.yahoo.com/info/terms/ > > --------------------------------- > |
|
Thanks for the info. But I'm still having problems.
Let me explain in a bit more detail.
I have a variable voltage coming into AN0 which I want to convert to
digital and output to PORTB. This is what is happening.
1. If the voltage coming into AN0 is 0v then PORTB is 0
2. If the voltage coming into AN0 is 5+v then PORTB is 255
3. Anything inbetween is giving weird values it looks
random. ????
I am using left justification as I'm only interested in 0 > 255 a
byte, then I read ADRESH and stick it to PORTB. There is probably
something that I'm doing wrong but I've tried a lot of different ideas
and cannot get this working.
Thanks again
Aaron
rtstofer <r...@pacbell.net> wrote:
|
A few things come to mind: did you fix the wait loop? In the example below it is backwards. Maybe your signal is noisy or has too much impedance. It is not recommended that the source impedance be below 10k (I think - check the datasheet). If possible run your signal through a 1K resistor between the source and the pin and then put a 0.1 ufd cap between the pin and ground. This will filter signals above about 10 kHz. Try a different pot if this is how you are generating your signal. For the heck of it, put a 1k resistor between the pin and Vcc and another 1k between the pin and ground. You should get a result on the order of 0x80. And it should be stable. You might try a few combinations of fixed resistors to be certain you code (and wait loop) is working properly. --- In , Aaron Morris <aaron_morris_2000@y...> wrote: > Thanks for the info. But I'm still having problems. Let me explain in a bit more detail. > > I have a variable voltage coming into AN0 which I want to convert to digital and output to PORTB. This is what is happening. > > 1. If the voltage coming into AN0 is 0v then PORTB is 0 > 2. If the voltage coming into AN0 is 5+v then PORTB is 255 > 3. Anything inbetween is giving weird values it looks random. ???? > > I am using left justification as I'm only interested in 0 > 255 a byte, then I read ADRESH and stick it to PORTB. There is probably something that I'm doing wrong but I've tried a lot of different ideas and cannot get this working. > > Thanks again > Aaron > > > rtstofer <rstofer@p...> wrote: > > The A/D converter is 10 bits wide - with left justification the upper > 8 bits are in ADRESH and the lower 2 bits in the upper 2 bits of > ADRESL. With right justification the upper 2 bits of the result are > in the lower 2 bits of ADRESH and the lower 8 bits are in ADRESL. > > Left justification, as you have it, is quite popular if you only need > to resolve 1 part in 256. No problem with dumping the lower 2 bits > unless you want to resolve 1 part in 1024. > --- In , Aaron Morris > wrote: > > Vasile, > > > > You are probably right as I am only reading ADRESH. Do I have to > Add both ADRESH + ADRESL to get the correct value. I'm not sure how > both of these registers work. Any information you know on this > subject is greatly welcomed. > > > > Thanks for your help > > Aaron > > > > > > Vasile Surducan wrote: > > > > > > How do you know if its a real 124 ? You are using only the first > most > > semnificative byte from adresh, and the result is left justified, > so you > > have lost the last two bits in adresl. Check if your delay have > indeed > > the required aquisition time of 20uS. > > > > top 10 wishes, > > Vasile > > http://surducan.netfirms.com > > > > > > On Tue, 15 Jul 2003, Aaron Morris wrote: > > > > > > > > Hi all, > > > > > > I have a little A/D program that gives me some results from an > analog sensor the problem is I get some strange values every so > often. For example If the sensor is reading a 124 an occasional lower > number seems to pop up. Any ideas of what this could be? Here's my > code so you get an idea of what I'm doing. > > > > > > Thanks > > > > > > Aaron > > > > > > CODE:::: > > > > > > > > > list pf877 > > > ERRORLEVEL -302 > > > #include "P16F877.INC" > > > > > > radix hex > > > > > > TEMP equ 0x0e > > > TEMP2 equ 0x0f > > > > > > > > > org 0x000 > > > start > > > movlw 0x00 > > > movwf PORTB > > > bsf STATUS, RP0 > > > clrf TRISB > > > movlw 0x00 > > > movwf TRISB > > > bcf STATUS, RP0 > > > clrf PORTB > > > > > > main > > > > > > call InitAD > > > > > > Update > > > movf ADRESH,w > > > movwf PORTB > > > call SetupDelay > > > > > > bsf ADCON0,GO > > > > > > loop > > > btfsc ADCON0,GO > > > goto Update > > > > > > goto loop > > > > > > return > > > > > > > > > SetupDelay > > > movlw 0x05 > > > movwf TEMP > > > SD > > > decfsz TEMP,f > > > goto SD > > > return > > > > > > > > > InitAD > > > bsf STATUS, 5 > > > movlw b'00001110' > > > movwf ADCON1 > > > bcf STATUS, 5 > > > movlw b'11000001' > > > movwf ADCON0 > > > clrf ADRESL > > > clrf ADRESH > > > clrf PORTB > > > return > > > > > > end > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --------------------------------- > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the > instructions > > > > ">http://docs.yahoo.com/info/terms/ > > > > > > > > > > --------------------------------- > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the instructions > > ">http://docs.yahoo.com/info/terms/ > > --------------------------------- > |