AM12864测试C语言程序
/*------------------延时子程序-----------------------------*/
void delay(unsigned int t)
{
unsigned int i,j;
for(i=0;it;i++) ;
for(j=0;j10;j++) ;
}
/*------------------写命令到LCD------------------------------*/
void write_com(unsigned char cmdcode)
{
do{delay(0);}while(P0^7==1);
Di=0;
RW=0;
Lcd_Bus=cmdcode;
delay(0); //原来是delay(0)
Enable=1;
delay(0);
Enable=0;
}
/*-------------------写数据到LCD----------------------------*/
void write_data(unsigned char Dispdata)
{ do{delay(10);}while(P0^7==1);
Di=1;
RW=0;
Lcd_Bus=Dispdata;
delay(0);
Enable=1;
delay(0);
Enable=0;
}
/*-------------------读LCD数据----------------------------*/
unsigned char read_data()
{ //do{delay(100);}while(P0^7==1);
unsigned char tmpin;
Di=1;
RW=1;
delay(0);
Enable=1;
delay(0);
Enable=0;do{delay(100);}while(P0^7==1);
tmpin=Lcd_Bus;
return tmpin;
}
/*------------------显示边框-------------------------------*/
void frame()
{
unsigned char i;
Mcs=1;
Scs=1;
write_com(Page_Add+0);
write_com(Col_Add+0);
for(i=0;i64;i++) write_data(0x01);
write_com(Page_Add+7);
write_com(Col_Add+0);
for(i=0;i64;i++) write_data(0x80);
for(i=0;i8;i++)
{
Mcs=0;
Scs=1;
write_com(Page_Add+i);
write_com(Col_Add+63);
write_data(0x55);
Mcs=1;
Scs=0;
write_com(Page_Add+i);
write_com(Col_Add+0);
write_data(0x55);
}
}
/*------------------清除内存AM12864测试程序---------------*/
void Clr_Scr()
{
unsigned char j,k;
Mcs=1;Scs=1;
write_com(Page_Add+0);
write_com(Col_Add+0);
for(k=0;k8;k++){
write_com(Page_Add+k);
for(j=0;j64;j++)write_data(0x00);
}
}
/*------------------显示12864图片---------------------------*/
void Disp_Img(unsigned char code *img)
{
unsigned char j,k;
for(k=0;k8;k++){
Mcs=1;Scs=0;delay(0);
write_com(Page_Add+k);
write_com(Col_Add+0);
for(j=0;j64;j++) write_data(img[k*128+j]);
Mcs=0;Scs=1; delay(0);
write_com(Page_Add+k);
write_com(Col_Add+0);
for(j=64;j128;j++) write_data(img[k*128+j]);
}
}
/*------------------显示横--------------AM12864测试程序-------------*/
void Disp_H_Line()
{
unsigned char i,j;
Mcs=1;
Scs=1;
write_com(Disp_On);
write_com(Page_Add);
write_com(Start_Line);
write_com(Col_Add);
for(j=0;j8;j++)
{
write_com(Page_Add+j);
write_com(Col_Add+0);
// write_com(Start_Line+0);
for(i=0;i64;i++)write_data(0x00);
}
}
/*------------------显示列-----------------------------*/
void Disp_V_Line()
{
unsigned char i,j;
write_com(Disp_On);
write_com(Page_Add);
write_com(Start_Line);
write_com(Col_Add);
for(j=0;j8;j++)
{
write_com(Page_Add+j);
write_com(Col_Add+0);
write_com(Start_Line+0);
for(i=0;i32;i++)
{
write_data(0x00);
write_data(0x55);
}
}
}
/*------------------棋盘-----------------------------*/
void Disp_Cross_Line(unsigned char mode)
{
unsigned char i,j;
unsigned char data1,data2;
if(mode==0) {data1=0xaa;data2=0x55;}
else if(mode==1) {data1=0x55;data2=0xaa;}
else return;
Mcs=1;Scs=1;
write_com(Disp_On);
write_com(Page_Add);
write_com(Start_Line);
write_com(Col_Add);
for(j=0;j8;j++)
{
write_com(Page_Add+j);
write_com(Col_Add+0);
write_com(Start_Line+0);
for(i=0;i32;i++){
write_data(data1);
write_data(data2);
}
}
}
/*---------------------指定位置显示汉字16*16-----------------------*/
void hz_disp16(unsigned char pag,unsigned char col, unsigned char code *hzk)
{
unsigned char j=0,i=0;
for(j=0;j2;j++){
write_com(Page_Add+pag+j);
write_com(Col_Add+col);
for(i=0;i16;i++) write_data(hzk[16*j+i]);
}
}
/*------------------初始化LCD屏--------------------------*/
void init_lcd()
{ Lcd_Rst=0;
delay(100);
Lcd_Rst=1;
delay(100);
Mcs=1;
Scs=1;/////////////////////////////////////////////////////////
delay(100);
write_com(Disp_Off); /////////////////////
write_com(Page_Add);
write_com(Start_Line);
write_com(Col_Add);
write_com(Disp_On);
}
/*------------------------------信息显示------------------------*/
void Msg(int flg)
{
Clr_Scr();
frame();
if(flg==0){ //显示"测试开始"
Mcs=1;Scs=0;
hz_disp16(3,32,ce);
delay(2000);
hz_disp16(3,48,shi);
delay(2000);
Mcs=0;Scs=1;
hz_disp16(3,0,kai);
delay(2000);
hz_disp16(3,16,shi2);
delay(2000);
}
else if(flg==1){ //显示"测试完毕"
Mcs=1;Scs=0;
hz_disp16(0,32,ce);
hz_disp16(0,48,shi);
Mcs=0;Scs=1;
hz_disp16(0,0,wan);
hz_disp16(0,16,bi);
Mcs=1;Scs=0;
hz_disp16(3,0,yang);
hz_disp16(3,16,qi);
hz_disp16(3,32,nong);
hz_disp16(3,48,du);
Mcs=0;Scs=1;
hz_disp16(3,0,bai);
hz_disp16(3,16,fen);
hz_disp16(3,32,bi2);
hz_disp16(3,48,wei);
- 基于TMS320C62X DSP的混合编程研究(07-12)
- 语音识别及其定点DSP实现(06-14)
- C语言编译过程中的错误分析(08-25)
- 单片机的图形化编程方法分析(05-03)
- 基于数字信号处理器的汇编程序优化方案(03-24)
- C语言在FPGA上实现DSP的解决方案(04-09)