EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Microchip Music example

Started by Stephen D. Barnes July 14, 2003
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
-----Original Message-----
From: Marcela Machado [mailto:b...@yahoo.com]
Sent: Tuesday, July 15, 2003 6:53 AM
To: p...@yahoogroups.com
Subject: [piclist] LCD and Keypad Interface

Hello, Can anybody help me?
I need a LCD and Keypad Interface code for pic16F876.
The LCD interface code i have. I dont know like i put
Keypad interface in my code.
Thank you
Marcela

_______________________________________________________________________
Yahoo! Mail
O melhor e-mail gratuito da internet: 6MB de espa, antivus, acesso POP3, filtro contra spam.
http://br.mail.yahoo.com/


to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

">Yahoo! Terms of Service.


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
----- Original Message -----
From: R.Stofer
To: p...@groups.yahoo.com
Sent: Tuesday, July 15, 2003 2:17 AM
Subject: [piclist] Re: Microchip Music Example - 16F628

Stephen,
 
Attached is code for the 16F628 using the internal 4MHz oscillator.  You can change the __CONFIG for your application.
 
I also initialized CMCON in 'Initialize' but I can not figure you why I have to toggle RA1 in the Loop code to make this thing work.  I also defined PORTA as having 8 bits with RA0 and RA1 as output.
 
I usually put toggle code in various spots like Loop and the beginning of InterruptEntry so I can check things with a scope.  That's how I discovered the code required at Loop.
 
It's late, I'll get back to it tomorrow.  In the meantime, the code works for me!
 
Richard


to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

">Yahoo! Terms of Service.



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

 

 


 

 



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:


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.comOn 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>
> ---------------------------------
>
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cidU11
http://us.click.yahoo.com/sOykFB/k9VGAA/ySSFAA/dN_tlB/TM
---------------------------------~-




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:

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 p...@yahoogroups.com, 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
>
> >
>
> ---------------------------------
>
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cidU11
http://us.click.yahoo.com/sOykFB/k9VGAA/ySSFAA/dN_tlB/TM
---------------------------------~-




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/
>
> ---------------------------------
>



The 2024 Embedded Online Conference