Hello.
I need some information about where to get some samples of a I2C
implementation for a 16f877 PIC with 32Kbit EEPROM model 24AA32A also
from Microchip.
Any comments or suggestions are welcome, until now, I haven't been
able to get it working, the PIC gets rebooted every time I execute the
routines.
I attach some of my code, I'm sorry, but's it's not well commented.
The functions are Serial*.
This is the main code which executes the functions, to be printed on a LCD:
for (i=0; i<16; i++)
{
for (j=0; j<40; j++)
{
result = (SerialRead(i,j)%112)+16;
PaintChar(result, j+1,i+1, MODE_EXOR);
}
}
Any ideas, people??
Thanks.
--
Néstor
+34 687 96 74 81
nesto...@gmail.com
#include "temete4.h"
#include "temete2.h"
void cmd(BYTE parameter)
{
WaitReady();
Save(CMD, parameter);
}
void dt2(BYTE h, BYTE l)
{
WaitReady();
Save(DATA, l);
WaitReady();
Save(DATA,h);
}
void dt1(BYTE inData)
{
WaitReady();
Save(DATA, inData);
}
void Save(bool param, BYTE data_) // SALVADATO
{
RD5 = param; //
TRISB = 0; // Output
PORTB = data_; //
RD7 = 0; // WR
RD6 = 1; // RD
RD4 = 0; // CE
Pause();
RD7 = 1; // WR
}
void PauseLong()
{
unsigned int i;
for ( i=0; i<=65000; i++ )
{
}
}
void PauseQuarterSecond()
{
BYTE i;
for ( i=0; i<=2; i++ )
{
PauseLong();
}
}
void Beep(BYTE mode)
{
unsigned int i;
char j;
BYTE cond;
TRISA0 = 0;
cond = 0;
j = 7;
while(j >= 0)
{
if (mode & (1 << j)) // Long beep
{
if (!cond)
{
for ( i=0; i<= 65000; i++ );
cond = 1;
}
for ( i=0; i<= 15000; i++ );
RA0 = 1;
for ( i=0; i<= 50000; i++ );
RA0 = 0;
}
else if (cond)
{
for ( i=0; i<= 15000; i++ );
RA0 = 1;
for ( i=0; i<= 10000; i++ );
RA0 = 0;
}
j--;
}
}
void BeepError(BYTE mode)
{
Beep(mode);
while(1);
}
void Pause()
{
BYTE i;
for ( i=0; i<=4; i++ )
{
}
}
void Sleep(BYTE steps)
{
BYTE i;
for (i=0; i<steps; i++)
{}
}
void WaitReady(void) /* LEER */
{
//BYTE accum;
BYTE byte0, byte1;
byte0 = 0;
byte1 = 0;
while(!(byte0 && byte1))
{
RD4 = 1; /* CE */
TRISB = 0x03; /* Input */
RD5 = 1; /* CMD */
RD7 = 1; /* WR */
RD6 = 0; /* RD */
RD4 = 0; /* CE */
Pause(); /* Pause */
byte0 = RB0;
byte1 = RB1;
RD6 = 1; /* RD */
RD4 = 1; /* CE */
}
}
void SerialStart()
{
TRISA = 0x02;
RA4 = 1;
RA3 = 1;
Sleep(100);
RA4 = 0;
Sleep(100);
RA3 = 0;
Sleep(100);
}
void SerialStop()
{
TRISA = 0x02;
RA3 = 0;
RA4 = 0;
Sleep(100);
RA3 = 1;
Sleep(100);
RA4 = 1;
Sleep(100);
}
void SerialByteSend(BYTE outData)
{
unsigned int i;
TRISA = 0x02;
RA4 = 0;
for (i=0; i<8; i++)
{
RA4 = (outData >> (7-i))&1;
Sleep(100);
RA3 = 1;
Sleep(200);
RA3 = 0;
Sleep(100);
}
RA4 = 0;
TRISA = 0x0a;
Sleep(100);
RA3 = 1;
Sleep(200);
RA3 = 0;
Sleep(100);
}
BYTE SerialByteRecv()
{
BYTE inData = 0x00;
BYTE i;
TRISA = 0x0a;
for (i=0; i<8; i++)
{
Sleep(100);
RA3 = 1;
Sleep(100);
if (RA4 == 1)
{
inData += (128>>i);
}
Sleep(100);
RA3 = 0;
Sleep(100);
}
TRISA = 0x02;
RA4 = 1;
Sleep(100);
RA3 = 1;
Sleep(200);
RA3 = 0;
Sleep(100);
RA4 = 0;
return inData;
}
void Borrar()
{
unsigned int hh,ll;
dt2(0,0);
cmd(ADPSET);
cmd(AWRON);
for (ll=0; ll<=255; ll++)
{
for (hh=0; hh<=45; hh++)
dt1(0x0); // 0x0: ' '
}
cmd(AWROFF);
}
void Paint(BYTE pattern[8], BYTE x, BYTE y)
{
BYTE i;
unsigned int pos;
pos = (((y-1)*40*8)+x-1)+640;
for (i=0; i<8; i++)
{
dt2((BYTE)(pos / 256),(BYTE)(pos % 256));
cmd(ADPSET);
dt1(pattern[i]);
cmd(0xc4);
pos = pos + 40;
}
}
/* Define processor and include header file. */
#ifndef TEMETE4_H
#define TEMETE4_H
#define A_OUTPUTS 0x02 /* value used to setup TRISA */
#define B_OUTPUTS 0x00 /* value used to setup TRISB */
#define C_OUTPUTS 0x08 /* value used to setup TRISC */
#define D_OUTPUTS 0x00 /* value used to setup TRISD */
#define E_OUTPUTS 0x00 /* value used to setup TRISE */
#define TXHOME 0x40
#define TXAREA 0x41
#define GRHOME 0x42
#define GRAREA 0x43
#define OFFSET 0x22
#define ADPSET 0x24
#define AWRON 0xB0
#define AWROFF 0xB2
#define CMDP 0x01
#define DP 0x00
#define DISP_GR_ON_TXT_ON 0x9c
#define MODE_OR 0x80
#define MODE_EXOR 0x81
#define MODE_AND 0x82
#define ALIGN_LEFT 0
#define ALIGN_RIGHT 1
#define ALIGN_CENTER 2
#define BEEP_START 1
#define BEEP_END 2
#define ERROR_LINEEND 3
#define ERROR_TEXTLENGTH 4
#define ERROR_TEXTPOS 5
#define ERROR_LOGO 6
#define DATA FALSE
#define CMD TRUE
#define __16f877
#include "pic/pic16f877.h"
typedef enum { FALSE, TRUE } bool;
typedef enum t_style{NORMAL, INVERTED} TStyle;
typedef unsigned char BYTE;
void cmd(BYTE parameter);
void Save(bool param, BYTE data_);
void dt2(BYTE h, BYTE l);
void dt1(BYTE inData);
void PauseLong();
void PauseQuarterSecond();
void Beep(BYTE mode);
void BeepError(BYTE mode);
void Pause();
void Sleep(BYTE steps);
void WaitReady(void); /* LEER */
void SerialStart();
void SerialStop();
void SerialByteSend(BYTE data);
BYTE SerialByteRecv();
BYTE SerialRead(BYTE addrH, BYTE addrL);
void Borrar();
void Paint(BYTE pattern[8], BYTE x, BYTE y);
#endif
------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user