Перейти к содержанию

Pix + I2C + Lc Display (Hd44780)


StasRadeon

Рекомендуемые сообщения

Люди добрые, помогите кто может!

потому что имею HD44780 + PCF8547, хотел сделать i2c library.

скажите пожалуйста где делаю неправильно.

прикрепляю PrintScreen от Proteus ISIS

#include <htc.h>
#define _XTAL_FREQ 4000000

//********************************************************
#pragma config FOSC = INTRC_CLKOUT// Oscillator Selection bits (INTOSC oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // RE3/MCLR pin function select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown Out Reset Selection bits (BOR enabled)
#pragma config IESO = OFF // Internal External Switchover bit (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
#pragma config LVP = ON // Low Voltage Programming Enable bit (RB3/PGM pin has PGM function, low voltage programming enabled)

// CONFIG2
#pragma config BOR4V = BOR40V // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
#pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off)

//********************************************************
#define LCD_DISPLAYMODE 0x08
#define pic_frq 16000 // controller frequenc
#define i2c_frq 400 //

#define gen_frq (((pic_frq / i2c_frq) / 4) - 1)
void i2cByteWrite(char, char, char);
void i2cTxData(char);
void LCD_dat(char);
void LCD_cmd(char);
void LCD_clr(void);
void LCD_int(void);
void LCD_str(char *);
void LCD_ROMstr(const char *);
void LCD_posyx(char,char);
void LCD_hex(char);
void i2c_init();
//////////// Main //////////////////////////////////
void main(void){
char msgStart[] ="LCD Work";
unsigned char num = 0;
OSCCON = 0b00110000; //4Mhz
TRISC = 0b11111111;
PORTC = 0x00;
i2c_init();
LCD_int();
// ------------------------------------------------------
LCD_str(msgStart); //
LCD_dat(' ');
LCD_dat('!');
// ------------------------------------------------------
LCD_posyx(1,0); //
LCD_ROMstr("12345");
while(1){
LCD_posyx(0,14); //
LCD_hex(num++); //
__delay_ms(1000); // 1000msec
}
}
void i2c_init()
{
TRISC3 = 1;
TRISC4 = 1;
SSPSTAT = 0b10000000; // Slew rate disabled
SSPCON = 0b00101000; //(0x28) SSPEN = 1, I2C Master mode, clock = FOSC/(4*(SSPADD+1))
SSPCON2 = 0b00000000; //
SSPADD = gen_frq;
}
// -----------------------------------------------------------
void i2cByteWrite(char addr, char cont, char data){
SEN = 1; // Start condition
while(SEN); // if (Start condition)
i2cTxData(addr); //
i2cTxData(cont); // 
i2cTxData(data); //
SSPIF = 0; // 
PEN = 1; // Stop condition
while(PEN); // Stop condition
}
void i2cTxData(char data){
SSPIF = 0; // 
SSPBUF = data; //
while(!SSPIF); //
}
// -----------------------------------------------------------
void LCD_dat(char chr){
i2cByteWrite(0xA0, 0x80, chr);
__delay_us(60); // 60 usec
}
// -----------------------------------------------------------
void LCD_cmd(char cmd){
i2cByteWrite(0xA0, 0x00, cmd);
if(cmd & 0xFC) // 
__delay_us(60); // 60usec
else
__delay_ms(3); // 3msec
}
// -----------------------------------------------------------
void LCD_clr(void){
LCD_cmd(0x01); //Clear Lcd
}
void LCD_posyx(char ypos, char xpos){
unsigned char pcode;
switch(ypos & 0x03){ // 
case 0: pcode=0x80;break; // 1line
case 1: pcode=0xC0;break; // 2line
case 2: pcode=0x94;break; // 3line
case 3: pcode=0xD4;break; // 4line
}
LCD_cmd(pcode += xpos); //
}
// -----------------------------------------------------------
void LCD_str(char *str){
while(*str) //
LCD_dat(*str++); //
}
// -----------------------------------------------------------
void LCD_ROMstr(const char *str){
while(*str) //
LCD_dat(*str++); //
}
// -----------------------------------------------------------
void LCD_hex(char c){
const char hexch[] ="aaaa";
LCD_dat(hexch[c >> 4]); //
LCD_dat(hexch[c & 0xF]); //
}
// -----------------------------------------------------------
void LCD_int(void){
__delay_ms(100); //
LCD_cmd(0x28); // 4 bit mode
LCD_cmd(LCD_DISPLAYMODE | 0x00); // Display on Cursor=0 Blink=0
LCD_cmd(0x06); // Entry Inc/Dec=1 Shift=0
LCD_cmd(0x01); // Clear Display
}

post-180370-0-75039200-1463750774_thumb.png

Ссылка на комментарий
Поделиться на другие сайты

Реклама: ООО ТД Промэлектроника, ИНН: 6659197470, Тел: 8 (800) 1000-321

Присоединяйтесь к обсуждению

Вы можете написать сейчас и зарегистрироваться позже. Если у вас есть аккаунт, авторизуйтесь, чтобы опубликовать от имени своего аккаунта.
Примечание: Ваш пост будет проверен модератором, прежде чем станет видимым.

Гость
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Ответить в этой теме...

×   Вставлено с форматированием.   Восстановить форматирование

  Разрешено использовать не более 75 эмодзи.

×   Ваша ссылка была автоматически встроена.   Отображать как обычную ссылку

×   Ваш предыдущий контент был восстановлен.   Очистить редактор

×   Вы не можете вставлять изображения напрямую. Загружайте или вставляйте изображения по ссылке.

Загрузка...
  • Последние посетители   0 пользователей онлайн

    • Ни одного зарегистрированного пользователя не просматривает данную страницу
×
×
  • Создать...