Привет! Помогите разобратся с ЖКИ, подключил правильно, но на экран ничего не выводится, горит только верхняя строка ;микроконтроллер SiLabs C8051F120, индикатор PYC1602AHW-SYL, думаю, что не проходит инициализация вот код
- Код: Выделить всё
#include "c8051F120.h"
#include <string.h>
#include <stdio.h>
sbit LCD_rs=P0^2;
sbit LCD_rw=P0^1;
sbit LCD_en=P0^0;
sbit LCD_D7=P2^7;
#define LCD_data P2
void Port_IO_Init(void);
void LCD_init(void);
void LCD_command(unsigned char var);
void LCD_busy(void);
void LCD_senddata(unsigned char var);
void LCD_sendstring(unsigned char *var);
void LCD_build();
unsigned char Mas[40];
void main (void)
{ int i;
for(i =0;i<35;i++) Mas[i] = 0;
strcpy(Mas,"0123456789ABCDEFGHJKL");
WDTCN = 0xDE;
WDTCN = 0xAD;
while (1){
Port_IO_Init();
LCD_init ();
LCD_sendstring (Mas);
LCD_build();
}
}
void Port_IO_Init()
{
SFRPAGE = CONFIG_PAGE;
P7MDOUT = 0xFF;
P5MDOUT = 0xFF;
XBR2 = 0x40;
}
void LCD_init()
{
LCD_data=0x38;
LCD_rs=0;
LCD_rw=0;
LCD_en=1;
LCD_en=0;
LCD_data=0x38;
LCD_rs=0;
LCD_rw=0;
LCD_en=1;
LCD_en=0;
LCD_busy();
LCD_data=0x0F;
LCD_rs=0;
LCD_rw=0;
LCD_en=1;
LCD_en=0;
LCD_busy();
LCD_data=0x01;
LCD_rs=0;
LCD_rw=0;
LCD_en=1;
LCD_en=0;
LCD_busy();
LCD_data=0x05;
LCD_rs=0;
LCD_rw=0;
LCD_en=1;
LCD_en=0;
LCD_en=1;
LCD_busy();
}
void LCD_busy()
{LCD_D7 = 1; //Make D7th bit of LCD as i/p
LCD_en = 1; //Make port pin as o/p
LCD_rs = 0; //Selected command register
LCD_rw = 1; //We are reading
while(LCD_D7){
LCD_en = 0; //Enable H->L
LCD_en = 1;}
/*unsigned char i,j;
for(i=0;i<500;i++) //A simple for loop for delay
for(j=0;j<255;j++);*/
}
void LCD_command(unsigned char var)
{
LCD_data = var;
LCD_rs = 0;
LCD_rw = 0;
LCD_en = 1;
LCD_en = 0;
LCD_busy();
}
void LCD_sendstring(unsigned char *var)
{ while(*var) //till string ends
LCD_senddata(*var++); //send characters one by one
}
void LCD_build()
{
LCD_command (0x48); //Load the location where we want to store
LCD_senddata(0x32); //Load row 1 data
LCD_senddata(0x0E); //Load row 2 data
LCD_senddata(0x0E); //Load row 3 data
LCD_senddata(0x0E); //Load row 4 data
LCD_senddata(0x1F); //Load row 5 data
LCD_senddata(0x00); //Load row 6 data
LCD_senddata(0x04); //Load row 7 data
LCD_senddata(0x00); //Load row
}
void LCD_senddata(unsigned char var)
{
LCD_data = var;
LCD_rs = 1;
LCD_rw = 0;
LCD_en = 1;
LCD_en = 0;
LCD_busy();
}