专注电子技术学习与研究
当前位置:单片机教程网 >> MCU设计实例 >> 浏览文章

AM12864测试程序

作者:佚名   来源:本站原创   点击数:  更新时间:2007年07月08日   【字体:

AM12864测试程序(C语言)

/********************************************/
/* AM12864测试程序 1.0 */
/* Designed by Andorin LCM R&D Group */
/********************************************/

#include <reg51.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
/********************************************/
/* AM12864测试程序 1.0 */
/* Designed by Andorin LCM R&D Group */
/********************************************/

/* Define the register command code */
#define Disp_On 0x3f
#define Disp_Off 0x3e
#define Col_Add 0x40
#define Page_Add 0xb8
#define Start_Line 0xc0
#define Lcd_Bus P1 //MCU P1<------> LCM
sbit Mcs=P2^3; //Master chip enable
sbit Scs=P2^4; //Slave chip enable
sbit Enable=P2^2; //6800 mode Enable single
sbit Di=P2^0; //Data or Instrument Select
sbit RW=P2^1; //Write or Read
sbit Lcd_Rst=P2^5; //Lcm reset
sbit Test_Key=P3^1;

char code ce[]={/*-- 文字: 测 --*/0x08,0x31,0x86,0x60,0x00,0xFE,0x02,0xF2,0x02,0xFE,0x00,0xF8,0x00,0x00,0xFF,0x00,
0x04,0xFC,0x03,0x00,0x80,0x47,0x30,0x0F,0x10,0x67,0x00,0x07,0x40,0x80,0x7F,0x00};
char code shi[]={/*-- 文字: 试 --*/0x40,0x42,0xDC,0x08,0x00,0x90,0x90,0x90,0x90,0x90,0xFF,0x10,0x12,0x1C,0x10,0x00,
0x00,0x00,0x7F,0x20,0x10,0x20,0x20,0x1F,0x10,0x10,0x01,0x06,0x18,0x20,0x78,0x00};
char code kai[]={/*-- 文字: 开 --*/0x40,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00};
char code shi2[]={0x10,0x90,0x70,0x1F,0x12,0xF0,0x00,0x20,0x70,0x28,0x27,0x22,0x28,0x70,0x20,0x00,
0x40,0x21,0x12,0x0C,0x06,0x09,0x30,0x00,0x7F,0x21,0x21,0x21,0x21,0x7F,0x00,0x00};//始
char code wan[]={0x00,0x90,0x8C,0xA4,0xA4,0xA4,0xA5,0xA6,0xA4,0xA4,0xA4,0xA4,0x94,0x8C,0x04,0x00,
0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x70,0x00,0x00};//完
char code bi[]={0x00,0x00,0xFF,0x88,0x48,0x28,0x08,0x80,0x7F,0x88,0x88,0x88,0x84,0x84,0xE0,0x00,
0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00};//毕
char code yang[]={0x20,0x10,0x2C,0x23,0x6A,0xAA,0x2A,0xAA,0x6A,0x2A,0x2A,0x2A,0xEA,0x02,0x00,0x00,
0x00,0x10,0x11,0x15,0x15,0x15,0xFF,0x15,0x15,0x15,0x11,0x10,0x3F,0x40,0x30,0x00};
char code qi[]={0x40,0x20,0x58,0x47,0x54,0x54,0x54,0x54,0x54,0x54,0xD4,0x14,0x06,0x04,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x40,0x80,0x70,0x00};//气
char code nong[]={0x10 ,0x21 ,0x62 ,0x06 ,0x90 ,0x0C ,0x04 ,0x84,0x64 ,0x9F ,0x04 ,0x04 ,0x94 ,0xCC ,0x00 ,0x00,
0x04 ,0x04 ,0xFE ,0x01 ,0x04 ,0x02 ,0x01 ,0xFF, 0x40 ,0x21 ,0x06 ,0x09 ,0x10 ,0x30 ,0x10 ,0x00 };//浓
char code du[]={0x00 ,0x00 ,0x0FC ,0x24 ,0x24 ,0x24 ,0x0FC ,0xA5, 0xA6 ,0xA4 ,0x0FC ,0x24 ,0x34 ,0x26 ,0x04 ,0x00,
0x40 ,0x20 ,0x9F ,0x80 ,0x42 ,0x42 ,0x26 ,0x2A, 0x12 ,0x2A ,0x26 ,0x42 ,0x40 ,0xC0 ,0x40 ,0x00};//度
char code bi2[]={0x00, 0x00, 0xFE, 0x40, 0x40, 0x60, 0x40, 0x00,0xFF, 0x80, 0x40, 0x20, 0x30, 0x00, 0x00, 0x00,
0x00, 0x40, 0x7F, 0x20, 0x20, 0x10, 0x10, 0x00,0x3F, 0x40, 0x40, 0x40, 0x40, 0x40, 0x78, 0x00};//比
char code fen[]={0x00 ,0x80 ,0x40 ,0x20 ,0x98 ,0x86 ,0x80 ,0x80,0x83 ,0x8C ,0x90 ,0x20 ,0xC0 ,0x80 ,0x80 ,0x00,
0x01 ,0x00 ,0x80 ,0x40 ,0x20 ,0x1F ,0x00 ,0x40, 0x80 ,0x40 ,0x3F ,0x00 ,0x00 ,0x01 ,0x00 ,0x00 };// 分
char code bai[]={0x02 ,0x02 ,0x02 ,0xE2 ,0x22 ,0x32 ,0x2A ,0x26,0x22 ,0x22 ,0x22 ,0xF2 ,0x22 ,0x03 ,0x02 ,0x00,
0x00 ,0x00 ,0x00 ,0xFF ,0x42 ,0x42 ,0x42 ,0x42, 0x42 ,0x42 ,0x42 ,0xFF ,0x00 ,0x00 ,0x00 ,0x00};// 百
char code wei[]={

0x20 ,0x20 ,0x20 ,0x22 ,0x24 ,0x2C ,0x20 , 0xE0,
0x3F ,0x20 ,0x20 ,0x20 ,0x20 ,0xF0 ,0x20 ,0x00,
0x00 ,0x40 ,0x20 ,0x10 ,0x08 ,0x04 ,0x03 ,0x00,
0x02 ,0x04 ,0x4C ,0x80 ,0x40 ,0x3F ,0x00 ,0x00
};//为

 

/*------------------延时子程序-----------------------------*/
void delay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++) ;
for(j=0;j<10;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;i<64;i++) write_data(0x01);
write_com(Page_Add+7);
write_com(Col_Add+0);
for(i=0;i<64;i++) write_data(0x80);
for(i=0;i<8;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;k<8;k++){
write_com(Page_Add+k);
for(j=0;j<64;j++)write_data(0x00);
}
}
/*------------------显示12864图片---------------------------*/
void Disp_Img(unsigned char code *img)
{
unsigned char j,k;
for(k=0;k<8;k++){
Mcs=1;Scs=0;delay(0);
write_com(Page_Add+k);
write_com(Col_Add+0);

for(j=0;j<64;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;j<128;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;j<8;j++)
{
write_com(Page_Add+j);
write_com(Col_Add+0);
// write_com(Start_Line+0);
for(i=0;i<64;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;j<8;j++)
{
write_com(Page_Add+j);
write_com(Col_Add+0);
write_com(Start_Line+0);
for(i=0;i<32;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;j<8;j++)
{
write_com(Page_Add+j);
write_com(Col_Add+0);
write_com(Start_Line+0);
for(i=0;i<32;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;j<2;j++){
write_com(Page_Add+pag+j);
write_com(Col_Add+col);
for(i=0;i<16;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);


}
}

/*--------------------------------键盘扫描-------------------------*/
void Key_Scan()
{
while(Test_Key);
while(~Test_Key);
}

/*--------------------主程序-----------AM12864测试程序----------------------*/

main()
{
unsigned char i=0;
while(1){
// Key_Scan();
init_lcd();
//Disp_Img(FirstPage);
//delay(10000);
// Key_Scan();
Msg(0);
delay(10000);
Disp_H_Line();
delay(10000);
Disp_V_Line();
delay(10000);

Msg(1);
delay(10000);
Clr_Scr();
//while(1);
}
}

关闭窗口

相关文章