CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

problem with 16f877a..write and read from external memory

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
doryme



Joined: 16 Oct 2010
Posts: 20

View user's profile Send private message

problem with 16f877a..write and read from external memory
PostPosted: Sat Nov 27, 2010 5:12 am     Reply with quote

Hello

I am using PIC16F877A. I want to write 8 bits in external memory, then read them again.
I enter 8 bits using 8 switches on PORTB, and read them on 8 leds on PORTD.

This is my simulation and my code(I am beginner Embarassed ) :



Code:
#INCLUDE <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#BYTE ADCON0=0x00
#BYTE ADCON1=0x07
#USE DELAY (CLOCK=10000000)
void main()
{
byte data0;
byte data1=0b00000000;
set_tris_b(0b11111111);
set_tris_a(0b11111111);
set_tris_e(0b00000000);
set_tris_d(0b00000000);

while(1)
{
if(input(pin_a0)&&!input(pin_a1))
    {
     set_tris_c(0b00000000);data0=input_b();output_c(data0);output_low(pin_e0);output_high(pin_e1);
    }
 else if(!input(pin_a0)&&input(pin_a1))
    {
     set_tris_c(0b11111111);output_high(pin_e0);output_low(pin_e1);data0=input_c();output_d(data0);
    }
 else
     {
      output_high(pin_e0);output_high(pin_e1);output_d(data1);
     }
}
}


The simulation works correctly, but why I get the error above?
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 27, 2010 11:49 am     Reply with quote

According to the datasheet, page 13, memorymap....
...address 009cx is NOT implemented (it physically does NOT exist).

Now as to WHERE your program does this....sorry, I only work with real hardware, not simulators.

However, since you are new...get rid of all those TRIS... functions, let the compiler handle it.
It is better to put one command/fucntion per line NOT all jammed up into one line with a buch of ;;;;;s ! It'll be easier to read and figure out what is going on !

Also use comments ! You might know what a line is doing now, but others don't and a day or two from now, you'll forget or mistake what that line is for. Been there- done that. When I code in assembly EVERY line has a comment, even obvious ones like clearing registers. With C I relax a bit, but not much.

Also it will help you to define NAMES to I/O pins. Again, something like RAM_OE is easier to understand what it's for than just PIN_E0.

The cleaner, neater, self-documented the code the easier it is in the long run.
doryme



Joined: 16 Oct 2010
Posts: 20

View user's profile Send private message

PostPosted: Sat Nov 27, 2010 3:51 pm     Reply with quote

temtronic wrote:
According to the datasheet, page 13, memorymap....
...address 009cx is NOT implemented (it physically does NOT exist).

Now as to WHERE your program does this....sorry, I only work with real hardware, not simulators.

However, since you are new...get rid of all those TRIS... functions, let the compiler handle it.
It is better to put one command/fucntion per line NOT all jammed up into one line with a buch of ;;;;;s ! It'll be easier to read and figure out what is going on !

Also use comments ! You might know what a line is doing now, but others don't and a day or two from now, you'll forget or mistake what that line is for. Been there- done that. When I code in assembly EVERY line has a comment, even obvious ones like clearing registers. With C I relax a bit, but not much.

Also it will help you to define NAMES to I/O pins. Again, something like RAM_OE is easier to understand what it's for than just PIN_E0.

The cleaner, neater, self-documented the code the easier it is in the long run.


Hello
Thank you for your help.
I connected the circuit on breadboard and it works very well!
I will the notes you said about my code in my mind for next times!Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group