#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pic.h>
#include <pic16f648a.h>
#include <xc.h>
#include "LCDlibrari.h"
// CONFIG
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator: Crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD)
#pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD enabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
void main(){
TRISA = 0x00;
TRISB = 0x00;
PORTA = 0x00;
PORTB = 0x00;
__delay_ms(1000);
LCD_init();
__delay_ms(1000);
LCD_letra("CASA");
while(1){
}
}
/*
* File: LCDlibrari.h
* Author: SERGIO
*
* Created on 9 de agosto de 2015, 22:53
*/
#define _XTAL_FREQ 8000000 //Frecuencia a 8Mhz
#define LCD_data PORTB
#define LCD_rs RA0
#define LCD_rw RA1
#define LCD_en RA2
void LCD_busyflag(){//Tiempo de espera y comprobacion de bandera
LCD_rs = 0;
LCD_rw = 1;
TRISB = 0x01; // puestos como entrada
LCD_en = 1; //habilita lcd
while(PORTBbits.RB7){ //comprueba que el D07 del lcd sea 1
}
LCD_en = 0;//deshabilita lcd
TRISB = 0x00; // Puertos como salida
LCD_rw = 0;
}
void LCD_letra(const unsigned char texto[] ){
int largo = strlen(texto);
int i=0;
unsigned char ch ;
for(i;largo>0;largo--&&i++){
ch = texto[i];
LCD_rs = 0;
LCD_rw = 0;
LCD_busyflag(); //Combpueba si esta ocupado
LCD_data = ch; //Caracter a escribir
LCD_rs = 1;
LCD_rw = 0;
LCD_en = 1;
LCD_en = 0;
__delay_us(40);
}
}
void LCD_clear(){
PORTBbits.RB7=0;
PORTBbits.RB6=0;
PORTBbits.RB5=0;
PORTBbits.RB4=0;
PORTBbits.RB3=0;
PORTBbits.RB2=0;
PORTBbits.RB1=0;
PORTBbits.RB0=1;
LCD_rs = 0;
LCD_rw = 0;
LCD_en = 1;
LCD_en = 0;
__delay_ms(2);
}
void LCD_home(){
PORTBbits.RB7=0;
PORTBbits.RB6=0;
PORTBbits.RB5=0;
PORTBbits.RB4=0;
PORTBbits.RB3=0;
PORTBbits.RB2=0;
PORTBbits.RB1=1;
PORTBbits.RB0=0;
LCD_rs = 0;
LCD_rw = 0;
LCD_en = 1;
LCD_en = 0;
__delay_ms(2);
}
void LCD_entry_set(){
PORTBbits.RB7=0;
PORTBbits.RB6=0;
PORTBbits.RB5=0;
PORTBbits.RB4=0;
PORTBbits.RB3=0;
PORTBbits.RB2=1;
PORTBbits.RB1=1;//1= Incrementa 0=Decrementa
PORTBbits.RB0=0;
LCD_rs = 0;
LCD_rw = 0;
LCD_en = 1;
LCD_en = 0;
__delay_us(50);
}
void LCD_on(){
PORTBbits.RB7=0;
PORTBbits.RB6=0;
PORTBbits.RB5=0;
PORTBbits.RB4=0;
PORTBbits.RB3=1;
PORTBbits.RB2=1;//1=ON 0=OFF
PORTBbits.RB1=1;//1=cursorON 0=CursorOFF
PORTBbits.RB0=0;//1=ParpadeoON 0=ParpadeoOFF
LCD_rs = 0;
LCD_rw = 0;
LCD_en = 1;
LCD_en = 0;
__delay_us(50);
}
void LCD_functionset(){
PORTBbits.RB7=0;//
PORTBbits.RB6=0;//
PORTBbits.RB5=1;//
PORTBbits.RB4=1;//1=8bit 0=4bit
PORTBbits.RB3=1;//1=2lineas 0=1linea
PORTBbits.RB2=0;//1=Celdat5x10 0=Celda5x8
PORTBbits.RB1=0;//
PORTBbits.RB0=0;//
LCD_rs = 0;
LCD_rw = 0;
LCD_en = 1;
LCD_en = 0;
__delay_us(50);
}
void LCD_in(){//FUNCION ESPECIAL DE INICIO LCD//
PORTBbits.RB7=0;//
PORTBbits.RB6=0;//
PORTBbits.RB5=1;//
PORTBbits.RB4=1;//
PORTBbits.RB3=0;//
PORTBbits.RB2=0;//
PORTBbits.RB1=0;//
PORTBbits.RB0=0;//
LCD_rs = 0;
LCD_rw = 0;
LCD_en = 1;
LCD_en = 0;
}
void LCD_setDDRAM(){//POSICION 0
PORTBbits.RB7=1;//
PORTBbits.RB6=0;//
PORTBbits.RB5=0;//
PORTBbits.RB4=0;//
PORTBbits.RB3=0;//
PORTBbits.RB2=0;//
PORTBbits.RB1=0;//
PORTBbits.RB0=0;//
LCD_rs = 0;
LCD_rw = 0;
LCD_en = 1;
LCD_en = 0;
__delay_ms(5);
}
void LCD_init(){
__delay_ms(500);
/////////////////////////////////////////////
/////////////Iniciar LCD/////////////////////
/////////////////////////////////////////////
__delay_ms(100);
LCD_in();
__delay_ms(50);
LCD_in();
__delay_ms(50);
LCD_functionset();
LCD_on();
LCD_clear();
LCD_entry_set();
LCD_home();
}
#include <pic16f628a.h>
#use delay (clock =4000000)
#use rs232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, BITS=8)
#use standard_io(a)
#use standard_io(b)
#include <lcd.c>
#fuses XT,NOWDT,PUT,MCLR,NOBROWNOUT NOLVP NOCPD, NOPROTECT
#define LCD_ENABLE_PIN PIN_B0
#define LCD_RS_PIN PIN_B1
#define LCD_RW_PIN PIN_B2
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7
void main(){
lcd_init();
output_low(PIN_A0);
if (input(PIN_A1)==0 ){
lcd_gotoxy(3,3);
lcd_putc("error" );
}
else(input(PIN_A1)==1 );{
lcd_gotoxy(2,1);
("no hay error" );
}
} CONFIG
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator: Crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD)
#pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD enabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
todo eso lo puedes poner en una sola linea asi
#fuses XT,NOWDT,MCLR,NOBROWNOUT NOLVP NOCPD, NOPROTECT,
Y ESTO while(1){} ESTA sobrando porque no hace nada pero cuando quieras usar un while cambiale el 1 por while(true){}
te falta #include <16f648a.h>
y para hacer entradas y salidas los puertos no se puede hacer asi en ccs tines que hacer lo siguiente
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
eso va al principio del programa despues de #use delay (clock =4000000) que define el reloj en 4MHZ todos los use van despues del use del clock
y ahora la forma correcta de poner los puertos set_tris_b(0x00); set_tris_a(0x00); con eso tu programa funcionaria mejor y usa la libreria <lcd.c> que viene en el picc compiler tambien se puede usar en el mpalb