بالاخره تونستم حلش کنم!!!
مشکل از این بود که من از پورت A برای EN و RS استفاده میکردم، پورت A آنالوگ است باید مقدار بیت های دو پین EN و RS را صفر در نظر میگرفتم تا پورت دیجیتال ست بشه!
وقتی که بیت ها دیجیتال ست نشده!
کد رو هم کمی تغییر دادم
lcd.h
کد:
#ifndef XC_HEADER_TEMPLATE_H
#define XC_HEADER_TEMPLATE_H
#include <xc.h> // include processor files - each processor file is guarded.
#define _XTAL_FREQ 4000000
#include <pic16f88.h>
// TODO Insert appropriate #include <>
// TODO Insert C++ class definitions if appropriate
// TODO Insert declarations
// Comment a function and leverage automatic documentation with slash star star
/**
*/
// TODO Insert declarations or function prototypes (right here) to leverage
// live documentation
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// TODO If C++ is being used, regular C code needs function names to have C
// linkage so the functions can be used by the c code.
#define LCD_RS RA3
#define LCD_EN RA4
#define LCD_DATA4 RB0
#define LCD_DATA5 RB1
#define LCD_DATA6 RB2
#define LCD_DATA7 RB3
#define LCD_PORT PORTB
void LCD_STROBE(void){
LCD_EN = 1;
__delay_us(1);
LCD_EN = 0;
}
void write(unsigned char value){
LCD_DATA4 = (value >> 0) & 0x01;
LCD_DATA5 = (value >> 1) & 0x01;
LCD_DATA6 = (value >> 2) & 0x01;
LCD_DATA7 = (value >> 3) & 0x01;
LCD_EN = 1;
__delay_us(1);
LCD_EN = 0;
}
void LCD_cmd(unsigned char data){
LCD_RS = 0;
__delay_us(50);
LCD_PORT = (data >> 4);
LCD_STROBE();
LCD_PORT = (data);
LCD_STROBE();
}
void LCD_goto(void){
LCD_cmd(0x80);
__delay_ms(2);
}
void LCD_clear(void){
LCD_cmd(0x01);
__delay_ms(2);
}
void LCD_char(unsigned char data){
LCD_RS = 1;
__delay_us(50);
write(data >> 4);
write(data);
}
void LCD_putc(unsigned char data){
LCD_RS = 1;
__delay_us(50);
LCD_PORT = (data >> 4);
LCD_STROBE();
LCD_PORT = (data);
LCD_STROBE();
}
void LCD_putcs(const char *data){
while (*data) {
LCD_putc(*data++);
}
}
void LCD_init(void){
TRISA3 = 0;
TRISA4 = 0;
TRISB = 0b11110000;
LCD_cmd(0x20); //4-bit 1 line, 2 line= 0x28
__delay_ms(1);
LCD_cmd(0x0c);
__delay_ms(1);
LCD_cmd(0x06); //cursor on
__delay_ms(2);
LCD_cmd(0x80); //cursor(0,0)
__delay_ms(2);
LCD_cmd(0x01); //clear
__delay_ms(2);
}
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* XC_HEADER_TEMPLATE_H */
main.c
کد:
#define _XTAL_FREQ 4000000
#include <pic16f88.h>
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include "lcd.h"
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Code protection off)
#pragma config CP = OFF
//TRISB
void main(void){
//TRISB6 = 0;
ANS3 = 0; //set RA3 to digital I/O
ANS4 = 0; //set RA4 to digital I/O
LCD_init();
LCD_goto();
LCD_putc('2');
__delay_ms(1000);
while (1) {
LCD_clear();
LCD_goto();
LCD_char('P');
__delay_ms(5000);
LCD_clear();
LCD_putcs("HELLO WORLD");
__delay_ms(5000);
LCD_clear();
}
}