16F877

Started by Paul_Lav July 4, 2003
Hi, i have been working with the 16F877 pic at work the last week and have a few questions.
 
1. EEPROM
 
I am trying use the eeprom to hold values in. I have some code that works with the 16F84A, i have transfered the code and changed all the banks, as some are different, but it won't work. Is there anything i should know about using it? I have looked at the datasheet and not seen anything majorly different?
 
2. The PIC resets for some reason?
 
I am using a display, press the mode button to change the display, 4 screens in a loop. All works fine but when displaying the last screen, only shows a few letters, then resets the pic? Why would this be?
 
3. This bit of code....
 
When the mode buttons is pressed, the program comes to the Mode_Change sub. Now the Mode_Bank is the number of the current bank. Now i put this in W. Call Mode_Get, skip either 1 or 2 instructions and return with the new mode. But i get a zero back? Any ideas. I have the program another way and it works, but for adding lots of different modes would make the program lengthy. This should shorten it
 
Mode_Get
 addwf PCL,f
 nop
 retlw b'00000010'  ;Mode 1. New Mode 2
 retlw d'00000001'  ;Mode 2. New Mode 1
 
Mode_Change
 call Clear_Display
 
 movfw Mode_Bank
 call Mode_Get
 movwf Mode_Bank
 call LCD_Lookup
 
 call Display
 goto Debounce
 retlw 0
 
 
Many thanks,
Paul



EEPROM - the code needs to be exactly as shown in sections 4.2 & 4.3
of the datasheet. It does work although in my own program I am only
reading EEPROM not writing it.

Table Lookup (Mode_Get) - Your code MAY work but probably not.
Download AN556 and write your code exactly as shown in Example 5.
This takes care of 8 bit overflow when adding something to PCL. Oh,
and when this doesn't work properly the program counter is set to
something unexpected and the results will be bizarre. --- In , "Paul_Lav" <paul_lav@y...> wrote:
> Hi, i have been working with the 16F877 pic at work the last week
and have a few questions.
>
> 1. EEPROM
>
> I am trying use the eeprom to hold values in. I have some code that
works with the 16F84A, i have transfered the code and changed all the
banks, as some are different, but it won't work. Is there anything i
should know about using it? I have looked at the datasheet and not
seen anything majorly different?
>
> 2. The PIC resets for some reason?
>
> I am using a display, press the mode button to change the display,
4 screens in a loop. All works fine but when displaying the last
screen, only shows a few letters, then resets the pic? Why would this
be?
>
> 3. This bit of code....
>
> When the mode buttons is pressed, the program comes to the
Mode_Change sub. Now the Mode_Bank is the number of the current bank.
Now i put this in W. Call Mode_Get, skip either 1 or 2 instructions
and return with the new mode. But i get a zero back? Any ideas. I
have the program another way and it works, but for adding lots of
different modes would make the program lengthy. This should shorten it
>
> Mode_Get
> addwf PCL,f
> nop
> retlw b'00000010' ;Mode 1. New Mode 2
> retlw d'00000001' ;Mode 2. New Mode 1
>
> Mode_Change
> call Clear_Display
>
> movfw Mode_Bank
> call Mode_Get
> movwf Mode_Bank
> call LCD_Lookup
>
> call Display
> goto Debounce
> retlw 0 > Many thanks,
> Paul




Hello!
 
Thanks for the reply.
 
I have now managed to get the EEPROM working, it me been daft! I was in the wrong bank for my data i wanted putting in!
 
I have downloaded the sheet and will give the code a go!
 
Another question... Does it matter what order the sub routines are in? e.g. If there is Sub1 calling Sub2 does Sub 2 have to be higher or lower or doesn't it matter?
 
Many thanks!
----- Original Message -----
From: rtstofer
To: p...@yahoogroups.com
Sent: Friday, July 04, 2003 6:35 PM
Subject: [piclist] Re: 16F877

EEPROM - the code needs to be exactly as shown in sections 4.2 & 4.3
of the datasheet.  It does work although in my own program I am only
reading EEPROM not writing it.

Table Lookup (Mode_Get) - Your code MAY work but probably not. 
Download AN556 and write your code exactly as shown in Example 5. 
This takes care of 8 bit overflow when adding something to PCL.  Oh,
and when this doesn't work properly the program counter is set to
something unexpected and the results will be bizarre.--- In p...@yahoogroups.com, "Paul_Lav" <paul_lav@y...> wrote:
> Hi, i have been working with the 16F877 pic at work the last week
and have a few questions.
>
> 1. EEPROM
>
> I am trying use the eeprom to hold values in. I have some code that
works with the 16F84A, i have transfered the code and changed all the
banks, as some are different, but it won't work. Is there anything i
should know about using it? I have looked at the datasheet and not
seen anything majorly different?
>
> 2. The PIC resets for some reason?
>
> I am using a display, press the mode button to change the display,
4 screens in a loop. All works fine but when displaying the last
screen, only shows a few letters, then resets the pic? Why would this
be?
>
> 3. This bit of code....
>
> When the mode buttons is pressed, the program comes to the
Mode_Change sub. Now the Mode_Bank is the number of the current bank.
Now i put this in W. Call Mode_Get, skip either 1 or 2 instructions
and return with the new mode. But i get a zero back? Any ideas. I
have the program another way and it works, but for adding lots of
different modes would make the program lengthy. This should shorten it
>
> Mode_Get
>  addwf PCL,f
>  nop
>  retlw b'00000010'  ;Mode 1. New Mode 2
>  retlw d'00000001'  ;Mode 2. New Mode 1
>
> Mode_Change
>  call Clear_Display
>
>  movfw Mode_Bank
>  call Mode_Get
>  movwf Mode_Bank
>  call LCD_Lookup
>
>  call Display
>  goto Debounce
>  retlw 0> Many thanks,
> Paul



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

">Yahoo! Terms of Service.


Hi, just been trying that code but i get a lot off errors. Could you help?
 
Mode_Change
 movfw Mode_Bank
 movwf Temp
 
 org 0x80
 movlw LOW Mode_Get
 addwf Temp,f
 
 movlw HIGH Mode_Get
 btfsc STATUS,C
 addlw 1
 movwf PCLATH
 movf Temp,w
 
 call Mode_Get
 movwf Mode_Bank
 
 org 0x9FD
 
 call Display
 goto Debounce
 
 retlw 0
 
Mode_Get
 movwf PCL,F
 nop
 retlw b'00000010'  ;Mode 1. New Mode 2
 retlw d'00000001'  ;Mode 2. New Mode 1
 
Many thanks,
Paul
----- Original Message -----
From: rtstofer
To: p...@yahoogroups.com
Sent: Friday, July 04, 2003 6:35 PM
Subject: [piclist] Re: 16F877

EEPROM - the code needs to be exactly as shown in sections 4.2 & 4.3
of the datasheet.  It does work although in my own program I am only
reading EEPROM not writing it.

Table Lookup (Mode_Get) - Your code MAY work but probably not. 
Download AN556 and write your code exactly as shown in Example 5. 
This takes care of 8 bit overflow when adding something to PCL.  Oh,
and when this doesn't work properly the program counter is set to
something unexpected and the results will be bizarre.--- In p...@yahoogroups.com, "Paul_Lav" <paul_lav@y...> wrote:
> Hi, i have been working with the 16F877 pic at work the last week
and have a few questions.
>
> 1. EEPROM
>
> I am trying use the eeprom to hold values in. I have some code that
works with the 16F84A, i have transfered the code and changed all the
banks, as some are different, but it won't work. Is there anything i
should know about using it? I have looked at the datasheet and not
seen anything majorly different?
>
> 2. The PIC resets for some reason?
>
> I am using a display, press the mode button to change the display,
4 screens in a loop. All works fine but when displaying the last
screen, only shows a few letters, then resets the pic? Why would this
be?
>
> 3. This bit of code....
>
> When the mode buttons is pressed, the program comes to the
Mode_Change sub. Now the Mode_Bank is the number of the current bank.
Now i put this in W. Call Mode_Get, skip either 1 or 2 instructions
and return with the new mode. But i get a zero back? Any ideas. I
have the program another way and it works, but for adding lots of
different modes would make the program lengthy. This should shorten it
>
> Mode_Get
>  addwf PCL,f
>  nop
>  retlw b'00000010'  ;Mode 1. New Mode 2
>  retlw d'00000001'  ;Mode 2. New Mode 1
>
> Mode_Change
>  call Clear_Display
>
>  movfw Mode_Bank
>  call Mode_Get
>  movwf Mode_Bank
>  call LCD_Lookup
>
>  call Display
>  goto Debounce
>  retlw 0> Many thanks,
> Paul



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

">Yahoo! Terms of Service.