发表于:2010/6/22 19:19:18
#0楼
//*******************************************
//**** 多功能PCB板测试机 ********
//**** ********
//****2010.6.19 STC90C58RD 12MHZ******
//P0 P4口做LCD显示HS320240
//***************************************************************************
#include <reg52.h>
#include <intrins.h>
sfr WDT_CONTR=0XE1;
sbit BRS=P4^6;
sbit BWR=P4^5;
sbit BRD=P4^4;
sbit BCS=P2^7;
unsigned char zhuanhuan[3];
#define DATA_BUS P0
unsigned char code str00[]="多 功 能 测 试 机";
unsigned char code str01[]="Version 1.00";
unsigned char code str02[]="温机NG, s";
unsigned char code str22[]=" ";
unsigned char code str03[]="感应NG, s";
unsigned char code str23[]=" ";
unsigned char code str04[]="LUX NG";
unsigned char code str24[]=" ";
unsigned char code str05[]="温机OK, s";
unsigned char code str06[]="感应OK, s";
unsigned char code str07[]="LUX OK";
unsigned char code str08[]="测 试 画 面";
unsigned char code str11[]="01";
unsigned char code str12[]="02";
unsigned char code str13[]="03";
unsigned char code str14[]="04";
unsigned char code str15[]="05";
unsigned char code str16[]="06";
unsigned char code str17[]="07";
unsigned char code str18[]="08";
unsigned char code str19[]="09";
unsigned char code str20[]="10";
unsigned char code str21[]="水滴灯测试规格:温机30~50秒,夜晚感应7~13秒,LUX为产品灯不亮";
bit m00=0;
unsigned int n00=0; //MS级计时
unsigned int miao00=0; //S级计时
unsigned int miao01=0;
unsigned int miao02=0;
unsigned int miao03=0;
unsigned int miao04=0;
unsigned int miao05=0;
unsigned int miao06=0;
unsigned int miao07=0;
unsigned int miao08=0;
unsigned int miao09=0;
unsigned int miao10=0; //S级计时
bit timepanding00=0; //温机最大时间判定用
bit timepanding01=0;
bit timepanding02=0;
bit timepanding03=0;
bit timepanding04=0;
bit timepanding05=0;
bit timepanding06=0;
bit wenji01=0; //温机判定变量
bit wenji02=0;
bit wenji03=0;
bit wenji04=0;
bit wenji05=0;
bit wenji06=0;
bit wenji07=0;
bit wenji08=0;
bit wenji09=0;
bit wenji10=0;
bit ganying01=0; //夜晚感应判定变量
bit ganying02=0;
bit ganying03=0;
bit ganying04=0;
bit ganying05=0;
bit ganying06=0;
bit ganying07=0;
bit ganying08=0;
bit ganying09=0;
bit ganying10=0;
bit lux01=0; //LUX测试变量
bit lux02=0;
bit lux03=0;
bit lux04=0;
bit lux05=0;
bit lux06=0;
bit lux07=0;
bit lux08=0;
bit lux09=0;
bit lux10=0;
bit xianshizhuanhuan=0;
unsigned int wenjinchuansong01=0;//传送变量 温机感应
unsigned int wenjinchuansong02=0;
unsigned int wenjinchuansong03=0;
unsigned int wenjinchuansong04=0;
unsigned int wenjinchuansong05=0;
unsigned int wenjinchuansong06=0;
unsigned int wenjinchuansong07=0;
unsigned int wenjinchuansong08=0;
unsigned int wenjinchuansong09=0;
unsigned int wenjinchuansong10=0;
unsigned int ganyingchuansong01=0;//传送变量 夜晚感应
unsigned int ganyingchuansong02=0;
unsigned int ganyingchuansong03=0;
unsigned int ganyingchuansong04=0;
unsigned int ganyingchuansong05=0;
unsigned int ganyingchuansong06=0;
unsigned int ganyingchuansong07=0;
unsigned int ganyingchuansong08=0;
unsigned int ganyingchuansong09=0;
unsigned int ganyingchuansong10=0;
bit tuidongqianxian=0; //推动前限
//===============================================
unsigned char code bmp1[];
unsigned char code b1[];
void LocateXY(unsigned char x,unsigned char y);
//===============================================
//写指令
void WriteCommand(unsigned char CommandReg,unsigned char CommandByte)
{
BCS = 0;
BRS = 0;
DATA_BUS = CommandReg;
BWR = 0;
BWR = 1;
DATA_BUS = CommandByte;
BWR = 0;
BWR = 1;
BCS = 1;
DATA_BUS = 0xff;
}
//写数据
void WriteData(unsigned char DataByte)
{
BCS = 0;
BRS = 1;
DATA_BUS = DataByte;
BWR = 0;
BWR = 1;
BCS = 1;
DATA_BUS = 0xff;
}
//延时函数
void delay(unsigned int MS)
{
unsigned char us,usn;
while(MS!=0)
{
usn = 2; //在12M晶振下接近1ms
while(usn!=0)
{
us=0xf9;
while (us!=0){us--;};
usn--;
}
MS--;
}
}
//初始化
void LcdInit(void)
{
WriteCommand(0x00,0xCD); //Power ON,TXT mode,Display ON
WriteCommand(0x01,0xF2); //Dis CLK_OUT,BUSY(INT) high,System clock 8MHz
WriteCommand(0x02,0x10); //ROM/RAM Speed1--60ns
WriteCommand(0x03,0x80); //Advance Display Setup
WriteCommand(0x10,0x29); //Align Disable;Bold Disable;Cursor Disable
WriteCommand(0x11,0x20); //Cursor high = 2;Row Distance = 0
WriteCommand(0x12,0x91); //Disable Gray,Only use Page1;page1 OR page2;R/W page1
WriteCommand(0x20,0x27); //Active window Right = (320/8)-1 = 39
WriteCommand(0x30,0xEF); //Active Window Bottom = 240-1 = 239
WriteCommand(0x40,0x00); //Active Window Left = 0
WriteCommand(0x50,0x00); //Active Window Top = 0
WriteCommand(0x21,0x27); //Display Window Right = (320/8)-1 = 39
WriteCommand(0x31,0xEF); //Display Window Bottom = 240-1 = 239
WriteCommand(0x41,0x00); //Display Window Left = 0
WriteCommand(0x51,0x00); //Display Window Top = 0
WriteCommand(0x60,0x00); //Cursor Position (X) = 0
WriteCommand(0x61,0x00); //Begin Segment Position = 0
WriteCommand(0x70,0x00); //Cursor Position (Y) = 0
WriteCommand(0x71,0x00); //Shift Begin Commom = 0
WriteCommand(0x72,0xEF); //Shift End Commom = 239
WriteCommand(0x80,0x33); //Blink Time = 51
WriteCommand(0x81,0x00); //N_line inverse start Common = 0
WriteCommand(0x91,0x00); //N_line inverse end Common = 0 (Disable)
WriteCommand(0x90,0x0C); //XCK (8MHz*4)/(240*320*70)= 6
WriteCommand(0xA0,0x00); //Interrupt Setup & Status (Disable all INT)
WriteCommand(0xA1,0x00); //Key Scan Disable
WriteCommand(0xA2,0x00); //Key Scan Data Register
WriteCommand(0xA3,0x00); //Key Scan Data Expand Register
WriteCommand(0xB0,0x27); //Interrupt Column = 39 (disabled)
WriteCommand(0xB1,0xEF); //Interrupt Row = 239 (disabled)
WriteCommand(0xC0,0x00); //Touch Panel Disable
WriteCommand(0xC1,0x0A); //ADC Status
WriteCommand(0xC8,0x80); //Touch Panel Segment High Byte Data Register(TPXR)
WriteCommand(0xC9,0x80); //Touch Panel Common High Byte Data Register(TPYR)
WriteCommand(0xCA,0x00); //Touch Panel Segment/Common Low Byte Data Register(TPZR)
WriteCommand(0xD0,0x18); //LCD Contrast Control = 24
WriteCommand(0xE0,0x00); //Fill Data = 00H
WriteCommand(0xF0,0xA0); //Font ROM Control
WriteCommand(0xF1,0x0F); //Font Size = x1
}
//清屏
void LcdClear(unsigned char y)
{
WriteCommand(0x12,0x93); //同时写入两层RAM
WriteCommand(0xE0,y);
WriteCommand(0xF0,0xA8);
delay(5);
WriteCommand(0x12,0x91); //修正
}
//坐标定位
void LocateXY(unsigned char x,unsigned char y)
{
WriteCommand(0x60,x);
WriteCommand(0x70,y);
}
//显示字符串函数
void PutStr(unsigned char x,unsigned char y,unsigned char *ptr)
{
LocateXY(x,y);
while(*ptr != '\0')
{
WriteData(*ptr);
++ptr;
}
}
//显示开关
void DisplaySW(unsigned char X)
{
if(X==0) WriteCommand(0x00,0xC9);
else WriteCommand(0x00,0xCD);
}
zuanhuan(unsigned int x1,unsigned int x2,unsigned int xx) //将数字转换成字符串并显示在LCD上
{
zhuanhuan[0]=xx/10+0x30;
zhuanhuan[1]=xx%10+0x30;
PutStr(x1,x2,zhuanhuan);
zhuanhuan[0]=0;
zhuanhuan[1]=0;
}
void zhuye()//显示器主页
{
delay(100);
WDT_CONTR=0X34;
LcdInit(); //初始化
LcdClear(0); //清屏
delay(5);
DisplaySW(1); //开显示
delay(5);
PutStr(12,0x60,str00);
PutStr(20,0xc0,str01);
delay(500);
delay(300);
WDT_CONTR=0X34;
delay(500);
WDT_CONTR=0X34;
LcdClear(0);
delay(3);
DisplaySW(1);
}
void chizhuye()//次主页
{ bit xunhuan00=0;
unsigned int xunhuan01=0;
PutStr(14,0x00,str08);//显示测试页面
while(0==xunhuan00)
{
PutStr(xunhuan01,0x24,str11);//01
PutStr(xunhuan01,0x34,str12);//02
PutStr(xunhuan01,0x44,str13);//03
PutStr(xunhuan01,0x54,str14);//04
PutStr(xunhuan01,0x64,str15);//05
PutStr(xunhuan01,0x74,str16);//06
PutStr(xunhuan01,0x84,str17);//07
PutStr(xunhuan01,0x94,str18);//08
PutStr(xunhuan01,0xa4,str19);//09
PutStr(xunhuan01,0xb4,str20);//10
if(28==xunhuan01)
xunhuan00=1;
if(14==xunhuan01)
xunhuan01=28;
if(0==xunhuan01)
xunhuan01=14;
WDT_CONTR=0X34;
}
PutStr(4,0xc4,str21);//产品规格
delay(200);
WDT_CONTR=0X34;
}
void miaorst() //秒变量清零
{
miao01=0;miao02=0;
miao03=0;miao04=0;
miao05=0;miao06=0;
miao07=0;miao08=0;
miao09=0;miao10=0;
miao00=0;
}
void bianliangqingling() //变量清零
{
WDT_CONTR=0X34;
miaorst();
wenji01=0; //温机判定变量
wenji02=0;
wenji03=0;
wenji04=0;
wenji05=0;
wenji06=0;
wenji07=0;
wenji08=0;
wenji09=0;
wenji10=0;
ganying01=0; //夜晚感应判定变量
ganying02=0;
ganying03=0;
ganying04=0;
ganying05=0;
ganying06=0;
ganying07=0;
ganying08=0;
ganying09=0;
ganying10=0;
lux01=0; //LUX测试变量
lux02=0;
lux03=0;
lux04=0;
lux05=0;
lux06=0;
lux07=0;
lux08=0;
lux09=0;
lux10=0;
timepanding00=0;
timepanding01=0;
timepanding02=0;
timepanding03=0;
timepanding04=0;
timepanding05=0;
timepanding06=0;
wenjinchuansong01=0;//传送变量 温机感应
wenjinchuansong02=0;
wenjinchuansong03=0;
wenjinchuansong04=0;
wenjinchuansong05=0;
wenjinchuansong06=0;
wenjinchuansong07=0;
wenjinchuansong08=0;
wenjinchuansong09=0;
wenjinchuansong10=0;
ganyingchuansong01=0;//传送变量 夜晚感应
ganyingchuansong02=0;
ganyingchuansong03=0;
ganyingchuansong04=0;
ganyingchuansong05=0;
ganyingchuansong06=0;
ganyingchuansong07=0;
ganyingchuansong08=0;
ganyingchuansong09=0;
ganyingchuansong10=0;
}
//**** 多功能PCB板测试机 ********
//**** ********
//****2010.6.19 STC90C58RD 12MHZ******
//P0 P4口做LCD显示HS320240
//***************************************************************************
#include <reg52.h>
#include <intrins.h>
sfr WDT_CONTR=0XE1;
sbit BRS=P4^6;
sbit BWR=P4^5;
sbit BRD=P4^4;
sbit BCS=P2^7;
unsigned char zhuanhuan[3];
#define DATA_BUS P0
unsigned char code str00[]="多 功 能 测 试 机";
unsigned char code str01[]="Version 1.00";
unsigned char code str02[]="温机NG, s";
unsigned char code str22[]=" ";
unsigned char code str03[]="感应NG, s";
unsigned char code str23[]=" ";
unsigned char code str04[]="LUX NG";
unsigned char code str24[]=" ";
unsigned char code str05[]="温机OK, s";
unsigned char code str06[]="感应OK, s";
unsigned char code str07[]="LUX OK";
unsigned char code str08[]="测 试 画 面";
unsigned char code str11[]="01";
unsigned char code str12[]="02";
unsigned char code str13[]="03";
unsigned char code str14[]="04";
unsigned char code str15[]="05";
unsigned char code str16[]="06";
unsigned char code str17[]="07";
unsigned char code str18[]="08";
unsigned char code str19[]="09";
unsigned char code str20[]="10";
unsigned char code str21[]="水滴灯测试规格:温机30~50秒,夜晚感应7~13秒,LUX为产品灯不亮";
bit m00=0;
unsigned int n00=0; //MS级计时
unsigned int miao00=0; //S级计时
unsigned int miao01=0;
unsigned int miao02=0;
unsigned int miao03=0;
unsigned int miao04=0;
unsigned int miao05=0;
unsigned int miao06=0;
unsigned int miao07=0;
unsigned int miao08=0;
unsigned int miao09=0;
unsigned int miao10=0; //S级计时
bit timepanding00=0; //温机最大时间判定用
bit timepanding01=0;
bit timepanding02=0;
bit timepanding03=0;
bit timepanding04=0;
bit timepanding05=0;
bit timepanding06=0;
bit wenji01=0; //温机判定变量
bit wenji02=0;
bit wenji03=0;
bit wenji04=0;
bit wenji05=0;
bit wenji06=0;
bit wenji07=0;
bit wenji08=0;
bit wenji09=0;
bit wenji10=0;
bit ganying01=0; //夜晚感应判定变量
bit ganying02=0;
bit ganying03=0;
bit ganying04=0;
bit ganying05=0;
bit ganying06=0;
bit ganying07=0;
bit ganying08=0;
bit ganying09=0;
bit ganying10=0;
bit lux01=0; //LUX测试变量
bit lux02=0;
bit lux03=0;
bit lux04=0;
bit lux05=0;
bit lux06=0;
bit lux07=0;
bit lux08=0;
bit lux09=0;
bit lux10=0;
bit xianshizhuanhuan=0;
unsigned int wenjinchuansong01=0;//传送变量 温机感应
unsigned int wenjinchuansong02=0;
unsigned int wenjinchuansong03=0;
unsigned int wenjinchuansong04=0;
unsigned int wenjinchuansong05=0;
unsigned int wenjinchuansong06=0;
unsigned int wenjinchuansong07=0;
unsigned int wenjinchuansong08=0;
unsigned int wenjinchuansong09=0;
unsigned int wenjinchuansong10=0;
unsigned int ganyingchuansong01=0;//传送变量 夜晚感应
unsigned int ganyingchuansong02=0;
unsigned int ganyingchuansong03=0;
unsigned int ganyingchuansong04=0;
unsigned int ganyingchuansong05=0;
unsigned int ganyingchuansong06=0;
unsigned int ganyingchuansong07=0;
unsigned int ganyingchuansong08=0;
unsigned int ganyingchuansong09=0;
unsigned int ganyingchuansong10=0;
bit tuidongqianxian=0; //推动前限
//===============================================
unsigned char code bmp1[];
unsigned char code b1[];
void LocateXY(unsigned char x,unsigned char y);
//===============================================
//写指令
void WriteCommand(unsigned char CommandReg,unsigned char CommandByte)
{
BCS = 0;
BRS = 0;
DATA_BUS = CommandReg;
BWR = 0;
BWR = 1;
DATA_BUS = CommandByte;
BWR = 0;
BWR = 1;
BCS = 1;
DATA_BUS = 0xff;
}
//写数据
void WriteData(unsigned char DataByte)
{
BCS = 0;
BRS = 1;
DATA_BUS = DataByte;
BWR = 0;
BWR = 1;
BCS = 1;
DATA_BUS = 0xff;
}
//延时函数
void delay(unsigned int MS)
{
unsigned char us,usn;
while(MS!=0)
{
usn = 2; //在12M晶振下接近1ms
while(usn!=0)
{
us=0xf9;
while (us!=0){us--;};
usn--;
}
MS--;
}
}
//初始化
void LcdInit(void)
{
WriteCommand(0x00,0xCD); //Power ON,TXT mode,Display ON
WriteCommand(0x01,0xF2); //Dis CLK_OUT,BUSY(INT) high,System clock 8MHz
WriteCommand(0x02,0x10); //ROM/RAM Speed1--60ns
WriteCommand(0x03,0x80); //Advance Display Setup
WriteCommand(0x10,0x29); //Align Disable;Bold Disable;Cursor Disable
WriteCommand(0x11,0x20); //Cursor high = 2;Row Distance = 0
WriteCommand(0x12,0x91); //Disable Gray,Only use Page1;page1 OR page2;R/W page1
WriteCommand(0x20,0x27); //Active window Right = (320/8)-1 = 39
WriteCommand(0x30,0xEF); //Active Window Bottom = 240-1 = 239
WriteCommand(0x40,0x00); //Active Window Left = 0
WriteCommand(0x50,0x00); //Active Window Top = 0
WriteCommand(0x21,0x27); //Display Window Right = (320/8)-1 = 39
WriteCommand(0x31,0xEF); //Display Window Bottom = 240-1 = 239
WriteCommand(0x41,0x00); //Display Window Left = 0
WriteCommand(0x51,0x00); //Display Window Top = 0
WriteCommand(0x60,0x00); //Cursor Position (X) = 0
WriteCommand(0x61,0x00); //Begin Segment Position = 0
WriteCommand(0x70,0x00); //Cursor Position (Y) = 0
WriteCommand(0x71,0x00); //Shift Begin Commom = 0
WriteCommand(0x72,0xEF); //Shift End Commom = 239
WriteCommand(0x80,0x33); //Blink Time = 51
WriteCommand(0x81,0x00); //N_line inverse start Common = 0
WriteCommand(0x91,0x00); //N_line inverse end Common = 0 (Disable)
WriteCommand(0x90,0x0C); //XCK (8MHz*4)/(240*320*70)= 6
WriteCommand(0xA0,0x00); //Interrupt Setup & Status (Disable all INT)
WriteCommand(0xA1,0x00); //Key Scan Disable
WriteCommand(0xA2,0x00); //Key Scan Data Register
WriteCommand(0xA3,0x00); //Key Scan Data Expand Register
WriteCommand(0xB0,0x27); //Interrupt Column = 39 (disabled)
WriteCommand(0xB1,0xEF); //Interrupt Row = 239 (disabled)
WriteCommand(0xC0,0x00); //Touch Panel Disable
WriteCommand(0xC1,0x0A); //ADC Status
WriteCommand(0xC8,0x80); //Touch Panel Segment High Byte Data Register(TPXR)
WriteCommand(0xC9,0x80); //Touch Panel Common High Byte Data Register(TPYR)
WriteCommand(0xCA,0x00); //Touch Panel Segment/Common Low Byte Data Register(TPZR)
WriteCommand(0xD0,0x18); //LCD Contrast Control = 24
WriteCommand(0xE0,0x00); //Fill Data = 00H
WriteCommand(0xF0,0xA0); //Font ROM Control
WriteCommand(0xF1,0x0F); //Font Size = x1
}
//清屏
void LcdClear(unsigned char y)
{
WriteCommand(0x12,0x93); //同时写入两层RAM
WriteCommand(0xE0,y);
WriteCommand(0xF0,0xA8);
delay(5);
WriteCommand(0x12,0x91); //修正
}
//坐标定位
void LocateXY(unsigned char x,unsigned char y)
{
WriteCommand(0x60,x);
WriteCommand(0x70,y);
}
//显示字符串函数
void PutStr(unsigned char x,unsigned char y,unsigned char *ptr)
{
LocateXY(x,y);
while(*ptr != '\0')
{
WriteData(*ptr);
++ptr;
}
}
//显示开关
void DisplaySW(unsigned char X)
{
if(X==0) WriteCommand(0x00,0xC9);
else WriteCommand(0x00,0xCD);
}
zuanhuan(unsigned int x1,unsigned int x2,unsigned int xx) //将数字转换成字符串并显示在LCD上
{
zhuanhuan[0]=xx/10+0x30;
zhuanhuan[1]=xx%10+0x30;
PutStr(x1,x2,zhuanhuan);
zhuanhuan[0]=0;
zhuanhuan[1]=0;
}
void zhuye()//显示器主页
{
delay(100);
WDT_CONTR=0X34;
LcdInit(); //初始化
LcdClear(0); //清屏
delay(5);
DisplaySW(1); //开显示
delay(5);
PutStr(12,0x60,str00);
PutStr(20,0xc0,str01);
delay(500);
delay(300);
WDT_CONTR=0X34;
delay(500);
WDT_CONTR=0X34;
LcdClear(0);
delay(3);
DisplaySW(1);
}
void chizhuye()//次主页
{ bit xunhuan00=0;
unsigned int xunhuan01=0;
PutStr(14,0x00,str08);//显示测试页面
while(0==xunhuan00)
{
PutStr(xunhuan01,0x24,str11);//01
PutStr(xunhuan01,0x34,str12);//02
PutStr(xunhuan01,0x44,str13);//03
PutStr(xunhuan01,0x54,str14);//04
PutStr(xunhuan01,0x64,str15);//05
PutStr(xunhuan01,0x74,str16);//06
PutStr(xunhuan01,0x84,str17);//07
PutStr(xunhuan01,0x94,str18);//08
PutStr(xunhuan01,0xa4,str19);//09
PutStr(xunhuan01,0xb4,str20);//10
if(28==xunhuan01)
xunhuan00=1;
if(14==xunhuan01)
xunhuan01=28;
if(0==xunhuan01)
xunhuan01=14;
WDT_CONTR=0X34;
}
PutStr(4,0xc4,str21);//产品规格
delay(200);
WDT_CONTR=0X34;
}
void miaorst() //秒变量清零
{
miao01=0;miao02=0;
miao03=0;miao04=0;
miao05=0;miao06=0;
miao07=0;miao08=0;
miao09=0;miao10=0;
miao00=0;
}
void bianliangqingling() //变量清零
{
WDT_CONTR=0X34;
miaorst();
wenji01=0; //温机判定变量
wenji02=0;
wenji03=0;
wenji04=0;
wenji05=0;
wenji06=0;
wenji07=0;
wenji08=0;
wenji09=0;
wenji10=0;
ganying01=0; //夜晚感应判定变量
ganying02=0;
ganying03=0;
ganying04=0;
ganying05=0;
ganying06=0;
ganying07=0;
ganying08=0;
ganying09=0;
ganying10=0;
lux01=0; //LUX测试变量
lux02=0;
lux03=0;
lux04=0;
lux05=0;
lux06=0;
lux07=0;
lux08=0;
lux09=0;
lux10=0;
timepanding00=0;
timepanding01=0;
timepanding02=0;
timepanding03=0;
timepanding04=0;
timepanding05=0;
timepanding06=0;
wenjinchuansong01=0;//传送变量 温机感应
wenjinchuansong02=0;
wenjinchuansong03=0;
wenjinchuansong04=0;
wenjinchuansong05=0;
wenjinchuansong06=0;
wenjinchuansong07=0;
wenjinchuansong08=0;
wenjinchuansong09=0;
wenjinchuansong10=0;
ganyingchuansong01=0;//传送变量 夜晚感应
ganyingchuansong02=0;
ganyingchuansong03=0;
ganyingchuansong04=0;
ganyingchuansong05=0;
ganyingchuansong06=0;
ganyingchuansong07=0;
ganyingchuansong08=0;
ganyingchuansong09=0;
ganyingchuansong10=0;
}