#include <18F8720.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES EC //External clock with CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOOSCSEN //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWAIT //Wait selections unavailable for Table Reads or Table Writes
#FUSES MCU //Microcontroller Mode
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)
aqui esta el .c
#include "D:\Pruebas1\Nueva carpeta\PRUEBALCD.h"
#include "D:\Pruebas1\Nueva carpeta\lcdnuevo.c"
void main()
{
#byte PORTE=0xF84
#byte lcd = 0xF84 // Direccion de la estructura "lcd".
//#byte lcd = 9 // Direccion del puerto d
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_timer_4(T4_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
lcd_init();
lcd_putc("hola mundo");
delay_ms(10000);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
// TODO: USER CODE!!
}
aqui esta la libreria lcd
///////////////////////////////////////////////////////////////////////////
// LCD
///////////////////////////////////////////////////////////////////////////
// E0 RS
// E1 ENABLE
// E4 D4
// E5 D5
// E6 D6
// E7 D7
// (Sin 'RW')
//
// Funciones soportadas:
// lcd_init()
// lcd_gotoxy( BYTE col, BYTE fila)
// lcd_putc( char c)
// \f Clear display
// \n Go to start of second line
// \b Move back one position
//
///////////////////////////////////////////////////////////////////////////
#define use_porte_lcd TRUE //LCD conectado al puerto b.
//
struct lcd_pin_map {
BOOLEAN rs; // RE0
BOOLEAN enable; // RE1
BOOLEAN unused1; // RE2
BOOLEAN unused2; // RE3
int data : 4; // RE4-RE7
} lcd;
//
#byte lcd = 0xF84 // Direccion de la estructura "lcd".
#define set_tris_lcd(x) set_tris_e(x)
#define lcd_type 2 // Tipo de LCD: 0=5x7, 1=5x10, 2=2 lineas
#define lcd_line_two 0x40 // Dirección de la LCD RAM para la 2da. linea
//
//Defino la cadena de inicializacion del LCD.
BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
//
//Configuro el estado de cada pin para lectura y escritura:
struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // Escribir.
struct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // Leer.
//
//Funciones:
BYTE lcd_read_byte() {
BYTE low,high;
set_tris_lcd(LCD_READ);
delay_cycles(1);
lcd.enable = 1;
delay_cycles(1);
high = lcd.data;
lcd.enable = 0;
delay_cycles(1);
lcd.enable = 1;
delay_us(1);
low = lcd.data;
lcd.enable = 0;
set_tris_lcd(LCD_WRITE);
return( (high<<4) | low);
}
//
void lcd_send_nibble( BYTE n ) {
lcd.data = n;
delay_cycles(1);
lcd.enable = 1;
delay_us(2);
lcd.enable = 0;
}
//
void lcd_send_byte( BYTE address, BYTE n ) {
lcd.rs = 0;
while ( bit_test(lcd_read_byte(),7) ) ;
lcd.rs = address;
delay_cycles(1);
delay_cycles(1);
lcd.enable = 0;
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
//
void lcd_init() {
BYTE i;
set_tris_lcd(LCD_WRITE);
lcd.rs = 0;
lcd.enable = 0;
delay_us(180);
for(i=1;i<=3;++i) {
lcd_send_nibble(3);
delay_us(60);
}
lcd_send_nibble(2);
for(i=0;i<=3;++i)
lcd_send_byte(0,LCD_INIT_STRING[i]);
}
//
void lcd_gotoxy( BYTE x, BYTE y) {
BYTE address;
if(y!=1)
address=lcd_line_two;
else
address=0;
address+=x-1;
lcd_send_byte(0,0x80|address);
}
//
void lcd_putc( char c) {
switch (c) {
case '\f' : lcd_send_byte(0,1);
delay_ms(2);
break;
case '\n' : lcd_gotoxy(1,2); break;
case '\b' : lcd_send_byte(0,0x10); break;
default : lcd_send_byte(1,c); break;
}
}