Friday, March 1, 2013
uso simple del lcd 2x16 C18
// USO DEL LCD
#include
#include
#include
#include
#define LCD_4X20 //usamos un LCD4x20
//Si usamos un LCD 16x2 quitamos el #define
//Fuses para trabajar con 8Mhz/////////
#pragma config FOSC = INTOSCIO_EC //usamos 8Mhz internos
#pragma config PLLDIV = 5 //PLL DIV 20Mhz/5=4Mhz
#pragma config CPUDIV = OSC1_PLL2 //CPUDIV1 96Mhz/2=48Mhz
#pragma config USBDIV = 1 //tRABAJAMOS CON USB CLOCK divido en 1
#pragma config VREGEN = OFF //Trabajamos sin regulador interno 3.3v para usb
//-----------------------------------------------------------------
#pragma config FCMEN = OFF, IESO = OFF
#pragma config PWRT = ON, BOR = OFF,BORV = 0
#pragma config WDT = OFF,WDTPS = 32768
#pragma config MCLRE = ON, LPT1OSC = OFF,PBADEN = OFF,CCP2MX = ON
#pragma config STVREN = OFF,LVP = OFF,XINST = OFF,DEBUG = OFF
#pragma config CP0 = OFF,CP1 = OFF,CP2 = OFF
#pragma config CPB = ON, CPD = ON
#pragma config WRT0 = OFF,WRT1 = OFF,WRT2 = OFF
#pragma config WRTB = OFF,WRTC = OFF,WRTD = OFF
#pragma config EBTR0 = OFF,EBTR1 = OFF,EBTR2 = OFF
#pragma config EBTRB = OFF
char buf[10];
int z,a=1,b=66;
////Funciones necesarias para uso del LCD /////
void DelayFor18TCY(void){
Delay10TCYx(4);
}
void DelayPORXLCD (void){
Delay1KTCYx(30); // Delay of 15ms
return; // Cycles = (TimeDelay * Fosc) / 4
// Cycles = (15ms * 8MHz) / 4
// Cycles = 30,000
}
void DelayXLCD (void){
Delay1KTCYx(10); // Delay of 5ms
return; // Cycles = (TimeDelay * Fosc) / 4
// Cycles = (5ms * 8MHz) / 4
// Cycles = 10,000
}
////Funcion de configuracion /////
void config(void){
OpenXLCD(FOUR_BIT & //4-bit
LINES_5X7); //
}
////Funcion de comandos para lcd/////
/// cd=0x01 clear screen /////
/// cd=0x0c ON creen /////
void cmdXLCD(unsigned char cd){
while(BusyXLCD());
WriteCmdXLCD(cd);
}
///Funcion de posicionamiento /////
/// x=renglon /////
/// y=columna /////
///Si queremos usar un lcd4x20 /////
///definimos despues del /////
///#include
///#define LCD_4X20 /////
#ifndef LCD_4X20
void gotoXYLCD(unsigned char x,unsigned char y){
unsigned char adr;
if(y!=1) adr=0x40;
else adr=0;
adr+=x-1;
cmdXLCD(0x80|adr);
}
#else
void gotoXYLCD(unsigned char x,unsigned char y){
unsigned char adr;
switch(y) {
case 1 : adr=0x80;break;
case 2 : adr=0xc0;break;
case 3 : adr=0x94;break;
case 4 : adr=0xd4;break;
}
adr+=x-1;
cmdXLCD(adr);
}
#endif
void main(void){
OSCCON=0x70;
config();
cmdXLCD(0x01);
putrsXLCD("A=1\n");
putrsXLCD("B=66");
gotoXYLCD(1,3);
putrsXLCD("z=A+B");
gotoXYLCD(1,4);
putrsXLCD("z=");
z=a+b;
itoa(z,buf);
gotoXYLCD(3,4);
putsXLCD(buf);
while(1);
}
Currently have 0 comentarios: