求看下程序,12864串口传输,其他脚位没错,只接lcd的SCLK,CS,SID这三个脚。网上程序也对比过好多了,不知道程序哪里出错了,求指导。
#include <STC15F2K60S2.H>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
/***********lcd 引脚定义*******************/
sbit SID = P1^5; //串行数据线
sbit SCLK = P3^4; //时钟线
sbit CS = P1^3; //片选
sbit LED = P5^5;
/*****************************************/
void delay_ms(unsigned int ms)
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<110;j++)
;
}
/*串行发送一个字节*/
void send_byte(uchar byte)
{
uchar i;
for(i=0;i<8;i++)
{
SCLK = 0; //上升沿触发
if((byte << i) & 0x80)
SID = 1;
else
SID = 0;
SCLK = 1;
_nop_();
}
}
/*写指令*/
void write_com(uchar com)
{
delay_ms(3); //该用检测忙
send_byte(0xf8); //1111 1000 MCU到LCD
delay_ms(3);
send_byte(com & 0xf0); //发送高字节
delay_ms(3);
send_byte((com << 4) & 0xf0);
delay_ms(5);
}
/*写数据*/
void write_data(uchar data1)
{
delay_ms(3); //该用检测忙
send_byte(0xfa); //1111 1010 显示数据
delay_ms(3);
send_byte(data1 & 0xf0);
delay_ms(3);
send_byte((data1 << 4) & 0xf0);
delay_ms(5);
}
void lcd_init()
{
delay_ms(200); //启动等待
write_com(0x30); //基本指令集 一次传8位
write_com(0x01); //清除显示DDRAM
write_com(0x02); //地址归0
delay_ms(50);
write_com(0x0c); //显示状态开关 开显示,显示光标,显示位反白闪动
write_com(0x80); //显示地址设为第一行首位
delay_ms(50);
}
void chinese_display(uchar line,uchar row,uchar data_h,uchar data_l)
{
write_com(0x01);
switch(line)
{
case 1:
{
write_com(0x80+row);
write_data(data_h);
write_data(data_l);
break;
}
case 2:
{
write_com(0x90+row);
write_data(data_h);
write_data(data_l);
break;
}
case 3:
{
write_com(0x88+row);
write_data(data_h);
write_data(data_l);
break;
}
case 4:
{
write_com(0x98+row);
write_data(data_h);
write_data(data_l);
break;
}
}
}
void num_display(uchar line,uchar row,uchar num)
{
write_com(0x01);
switch(line)
{
case 1:
{
write_com(0x80+row);
write_data(0x30+num);
break;
}
case 2:
{
write_com(0x90+row);
write_data(0x30+num);
break;
}
case 3:
{
write_com(0x88+row);
write_data(0x30+num);
break;
}
case 4:
{
write_com(0x98+row);
write_data(0x30+num);
break;
}
}
}
void main()
{
lcd_init();
LED = 0;
delay_ms(100);
num_display(1,1,3);
delay_ms(200);
}
-
这是接法
一周热门 更多>