kari0052
Joined: 04 Jul 2010 Posts: 1
|
9356 eeprom |
Posted: Sun Jul 04, 2010 4:19 pm |
|
|
Hi, I have difficulties to make modification to my project which use 16F877 to read and write to external eeprom 9356. It works when I use two pins to read and write. But I need to use two pins of Port B to read and write (short the pins 3 and 4 on the eeprom 9356).
My code is as follow:
Code: |
#include <prototype.h>
#include <utility.c>
#include <9356.c>
#include <stdio.h>
#use rs232 ( baud=9600, xmit=PIN_C6, rcv=PIN_c7 )
/********************** main *************************/
void main ()
{ // start main
int count;
init_ext_eeprom();
count = read_ext_eeprom(0);
while ( TRUE )
{ // while ( TRUE )
show_binary_on_leds ( count );
wait_for_one_press ();
count++;
write_ext_eeprom ( 0, count );
if (count >7)
{
count=0;
}
printf("count is %u\r\n", count);
} // while ( TRUE )
} // End main
|
The code count BCD when press the push button, and should keep the last count if i disconnect the power and connect it back. It is doing that now, but when I short the two pins of the 9356 it is not functioning.
This is the Utility.c code
Code: |
show_binary_on_leds(int n)
{
// show_binary_on_leds(int n)
output_high(green_led);
output_high(yellow_led);
output_high(red_led);
if(bit_test(n, 0))
output_low(green_led);
if(bit_test(n, 1))
output_low(yellow_led);
if(bit_test(n, 2))
output_low (red_led);
}
// show_binary_on_leds(int n)
void wait_for_one_press()
{
while(input(push_button));
delay_ms(100); // Used to debounce PB
while(!input(push_button));
} // end wait for one press
|
This is the Prototype.h
Code: |
#include <16f877A.h>
#device ICD=TRUE
#fuses HS, NOLVP, NOWDT, PUT
#use delay ( clock = 20000000 )
#define green_led PIN_A5 // The green led is connected to A5 (pin 8)
#define yellow_led PIN_B4 // The yellow led is connected to B4 (pin 41)
#define red_led PIN_B5 // The red led is connected to B5 (pin 42)
#define push_button PIN_A4 // Push button connected to A4 (pin 7)
#use rs232 (baud-9600, xmit=PIN_C6, rcv=PIN_C7) //Used for serial communication
|
This is to help you understand the whole code.
I appreciate your help
Thanks |
|