微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机I2C通信及LCD1602显示C程序

单片机I2C通信及LCD1602显示C程序

时间:12-02 来源:互联网 点击:

dula = 1;
P0 = table[bai];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfe;
wela = 0;
P0 = 0x00;
delay(1);

dula = 1;
P0 = table[shi];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfd;
wela = 0;
P0 = 0x00;
delay(1);

dula = 1;
P0 = table[ge];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfb;
wela = 0;
P0 = 0x00;
delay(1);
}
/********************************************************************/
/*************************UART串口通信******************************/
/********************************************************************/
//uart:initUART初始化
void uart_init()
{
TMOD = 0x20;
TH1 = 0xFD; //9600bps/s
TL1 = 0xFD;
TR1 = 1;
SM0 = 0;
SM1 = 1;
REN = 1;
EA = 1;
ES = 1;
}
//main:主程序
void main(void)
{
i2c_init();
lcd_init();
uart_init();
//LCD1602
write_cmd(0x80);
send_string(string_1);
write_cmd(0x80 + 0x40);
send_string(string_2);
//AT24C02
write_c02(0x0a, 0xaa);
num = read_c02(0x0a);
while(1)
{
display(num);
if(flag == 1)
{
ES = 0;
SBUF = num;
while(!TI);
TI = 0;
flag = 0;
ES = 1;
}
}
}
//UART:INT 串口中断程序
void uart_int() interrupt 4
{
RI = 0;
num = SBUF;
flag= 1;
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top