BUENO A VER SI ME PUEDEN AYUDAR, ESTOY TRATANDE DE INICIALIZAR EL LCD 16X2 PERO NO ME ESTA FUNCIONANDO Y LA VERDAD YA NO SE QUE ´PUEDA SER, PUES ANTES FUNCIONABA BIEN, Y NO ES PROBLEMA NI DE PUERTOS NI DEL LCD AYUDA POR FAVOR ES URGENTE
AQUI ESTA EL CODIGO.
//*----------------------------------------------------------------------------
//* SanJaaC Electronics
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name : main.c
//* Object : Main application written in C
//*----------------------------------------------------------------------------
// Include Standard LIB files
#include "Drivers.h"
#include "SJ-AT91SAM7SBoard.h"
#include "Dbgu.h"
extern UInt16 adcBuff_0[ADC_BUFF_LEN];
extern UInt16 adcBuff_1[ADC_BUFF_LEN];
#define WAIT_TIME MCK
extern int ban=0;
extern char n=0;
int menu=0;
int P3,P4,p;
void LCDSendInt(int a);
void delay (int divisor);
void LCDSendTxt(char* a);
void LCDSendChar(unsigned long a);
void LCDSendCommand(unsigned long a);
void LCDInit();
void Delay_mS (unsigned long a);
void E_Pulse();
#define BIT16 0x00010000
#define BIT17 0x00020000
#define BIT18 0x00040000
#define BIT19 0x00080000
#define BIT20 0x00100000
#define BIT21 0x00200000
#define BIT22 0x00400000
#define CLR_DISP 0x00000001
#define DISP_ON 0x0000000C
#define DISP_OFF 0x00000008
#define CUR_HOME 0x00000002
#define CUR_OFF 0x0000000C
#define CUR_ON_UNDER 0x0000000E
#define CUR_ON_BLINK 0x0000000F
#define CUR_LEFT 0x00000010
#define CUR_RIGHT 0x00000014
#define CUR_UP 0x00000080
#define CUR_DOWN 0x000000C0
#define ENTER 0x000000C0
#define DD_RAM_ADDR 0x00000080
#define DD_RAM_ADDR2 0x000000C0
unsigned long data;
AT91PS_PIO l_pPio = AT91C_BASE_PIOA;
//------------------------------
//arrancamos un nuevo programa
//-------------------------------
int main (void){
char* dataBuff = NULL;
int i,o,pata,j;
// Initialize system
System_init ();
// Init digital IO
DigitalIO_init (0, AT91C_PIO_PA16|AT91C_PIO_PA17|AT91C_PIO_PA18|AT91C_PIO_PA19|AT91C_PIO_PA20|AT91C_PIO_PA21|AT91C_PIO_PA22);
l_pPio->PIO_CODR = BIT16|BIT17|BIT18|BIT19|BIT20|BIT21|BIT22;
delay(100);
LCDInit(); //LCD Initialization
LCDSendCommand(CLR_DISP);
LCDSendCommand(DD_RAM_ADDR);
DigitalIO_clear (LED3);
LCDSendCommand(CLR_DISP);
LCDSendTxt(" Bienvenido");
delay(50);
}
void LCDInit()
{
// First set D4, D5, D6, D7, RS, RW, E to output ports + BIT23 (light)
l_pPio->PIO_OER = (BIT16|BIT17|BIT18|BIT19|BIT20|BIT21|BIT22);
// Enable D4, D5, D6, D7, RS, RW, E ports + BIT23 (light)
l_pPio->PIO_PER = (BIT16|BIT17|BIT18|BIT19|BIT20|BIT21|BIT22);
l_pPio->PIO_CODR = BIT20|BIT21|BIT22; //clear RS, E, RW
delay(390); //delay ~110ms
l_pPio->PIO_SODR = BIT16|BIT17; //set D4 and D5 port to 1
E_Pulse(); //high->low to E port (pulse)
delay(4286); //delay ~10ms
l_pPio->PIO_SODR = BIT16|BIT17; //set D4 and D5 port to 1
E_Pulse(); //high->low to E port (pulse)
delay(4286); //delay ~10ms
l_pPio->PIO_SODR = BIT16|BIT17; //set D4 and D5 port to 1
E_Pulse(); //high->low to E port (pulse)
delay(4286); //delay ~10ms
l_pPio->PIO_CODR = BIT16; //set D4 port to 0
l_pPio->PIO_SODR = BIT17; //set D5 port to 1
E_Pulse(); //high->low to E port (pulse)
delay(4286); //delay ~10ms
}
void LCDSendCommand(unsigned long a)
{
l_pPio->PIO_CODR = BIT22; //set RW port to 0
delay(6000); //delay for LCD char ~2ms
data = 0x0; //clear data
data = 0xffffff0f | a; //get high 4 bits
l_pPio->PIO_CODR = BIT16|BIT17|BIT18|BIT19; //clear D4-D7
data = data << 12; //shift data
l_pPio->PIO_SODR = 0x000f0000 & data; //set data
l_pPio->PIO_CODR = BIT20; //set RS port to 0 -> display set to comand mode
E_Pulse(); //pulse to set d4-d7 bits
data = 0x0; //clear data
a = a<<4; //shift to get low 4 bits
data = 0xffffff0f | a; //get low 4 bits
l_pPio->PIO_CODR = BIT16|BIT17|BIT18|BIT19; //clear D4-D7
data = data << 12; //shift data
l_pPio->PIO_SODR = 0x000f0000 & data; //set D4-D7
l_pPio->PIO_CODR = BIT20; //set RS port to 0 -> display set to comand mode
E_Pulse(); //pulse to set d4-d7 bits
}
void LCDSendChar(unsigned long a)
{
l_pPio->PIO_CODR = BIT22; //set RW port to 0
delay(6000); //delay for LCD char ~2ms
data = 0x0; //clear data
data = 0xffffff0f | a; //get high 4 bits
l_pPio->PIO_CODR = BIT16|BIT17|BIT18|BIT19; //clear D4-D7
data = data << 12; //shift data
l_pPio->PIO_SODR = 0x000f0000 & data; //set data
l_pPio->PIO_SODR = BIT20; //set RS port to 1 -> display set to character mode
E_Pulse(); //pulse to set d4-d7 bits
data = 0x0; //clear data
a = a<<4; //shift to get low 4 bits
data = 0xffffff0f | a; //get low 4 bits
l_pPio->PIO_CODR = BIT16|BIT17|BIT18|BIT19; //clear D4-D7
data = data << 12; //shift data
l_pPio->PIO_SODR = 0x000f0000 & data; //set D4-D7
l_pPio->PIO_SODR = BIT20; //set RS port to 1 -> display set to character mode
E_Pulse(); //pulse to set d4-d7 bits
}
void LCDSendTxt(char* a)
{
for(int i=0; i<strlen(a); i++)
{
LCDSendChar(a
);
}
}
void LCDSendInt(int a)
{
int h = 0;
int l = 0;
int r = 0;
l = a%10;
h = a/10;
h = h%10;
r = a/100;
r = r%10;
LCDSendChar(r+48);
LCDSendChar(h+48);
LCDSendChar(l+48);
}
void E_Pulse()
{
l_pPio->PIO_SODR = BIT21; //set E to high
delay(9000) ; //delay
l_pPio->PIO_CODR = BIT21; //set E to low
}
void delay (int divisor)
{
//* Set in Volatile for Optimisation
volatile unsigned int i ;
//* loop delay
for ( i = 0 ;(i < WAIT_TIME/divisor );i++ ) ;
}
void Delay_mS (unsigned long a) { while (--a!=0); }