/*****************NY8LP05A*************************/
/*****************LCD_GDC04212S********************/
/*****************ID:共同学习stm8*******************/
/*****************20241001*************************/
/**************************************************/
// _1A_ ____GDC04212S___ ____
// | 1 | | 2 | | 3 | | 4 |
// 1F 1B | | . | | | |
// |-1G-| |----| 2H |----| |----|
// 1E 1C | | . | | | |
// |_1D_|.1H |____|.3H |____|.4H |____|
// 1[url=home.php?mod=space&uid=72445]@[/url] 2@ 3@ 4@ 5@ 6@ 7@ 8@ 9@ 10@ 11@ 12@
// 段码屏脚位________________________________________________________
//|_PIN_|_1__|_2__|_3__|_4__|_5__|_6__|_7__|_8__|_9__|_10_|_11_|_12_|
//|COM0_|COM0|____|____|____|_1F_|_1A_|_2F_|_2A_|_3F_|_3A_|_4F_|_4A_|
//|COM1_|____|COM1|____|____|_1G_|_1B_|_2G_|_2B_|_3G_|_3B_|_4G_|_4B_|
//|COM2_|____|____|COM2|____|_1E_|_1C_|_2E_|_2C_|_3E_|_3C_|_4E_|_4C_|
//|COM3_|____|____|____|COM3|_1H_|_1D_|_2H_|_2D_|_3H_|_3D_|_4H_|_4D_|
//ram位置 ________________________________________________
// |_0x200_|_4A_|_4F_|_3A_|_3F_|_2A_|_2F_|_1A_|_1F_|
// |_0x208_|_4B_|_4G_|_3B_|_3G_|_2B_|_2G_|_1B_|_1G_|
// |_0x210_|_4C_|_4E_|_3C_|_3E_|_2C_|_2E_|_1C_|_1E_|
// |_0x218_|_4D_|_4H_|_3D_|_3H_|_2D_|_2H_|_1D_|_1H_|
/**************************************************/
#include <ny8l.h>
/**************************************************/
#define led_l PB&=~(1<<0)
#define led_h PB|=(1<<0)
#define anjian PA&(1<<0)
/**************************************************/
void yanshi(unsigned char z1); //延时
void chushihua(); //初始化
void xianshi(); //显示
void caidan(); //菜单
/**************************************************/
unsigned char xianshi_a1; //显示RAM变量
unsigned char xianshi_a2;
unsigned char xianshi_a3;
unsigned char xianshi_a4;
/**************************************************/
unsigned char const zi1[]={
0x3f, //0,0
0x06, //1,1
0x5b, //2,2
0x4f, //3,3
0x66, //4,4
0x6d, //5,5
0x7d, //6,6
0x07, //7,7
0x7f, //8,8
0x6f, //9,9
0x77, //10,a
0x7c, //11,b
0x39, //12,c
0x5e, //13,d
0x79, //14,e
0x71, //15,f
0x3d, //16,g
0x76, //17,h
0x04, //18,i
0x1e, //19,j
0x78, //20,k
0x38, //21,l
0x55, //22,m
0x54, //23,n
0x5c, //24,o
0X73, //25,p
0X67, //26,q
0X50, //27,r
0X6d, //28,s
0X31, //29,t
0X3e, //30,u
0X1c, //31,v
0X1d, //32,w
0X52, //33,x
0X6e, //34,y
0X5b, //35,z
0x00, //36,不显
0b10000000, //37,.
0b01000000, //38,-
0b01111110 //39,廿
};
/**************************************************/ //元素数量+元素位置+不显*4
unsigned char const caidan1[]={ 9,1,38,23,18,17,10,24,36,36,36,36}; //1.nihao
unsigned char const caidan2[]={13,2,38,20,10,18,16,30,10,23,19,18,36,36,36,36}; //2.kaiguanji
unsigned char const caidan3[]={18,3,38,32,14,23,13,30,28,17,10,23,16,33,18,10,23,36,36,36,36}; //3.wendushangxian
unsigned char const caidan4[]={16,4,38,32,14,23,13,30,33,18,10,33,18,10,23,36,36,36,36}; //4.wenduxiaxian
unsigned char const caidan5[]={11,5,38,28,17,18,19,18,10,23,36,36,36,36}; //5.shijian
unsigned char const caidan6[]={13,6,38,19,18,10,24,35,17,14,23,16,36,36,36,36}; //6.jiaozheng
unsigned char const caidan7[]={16,7,38,19,18,10,28,30,28,17,18,19,18,10,23,36,36,36,36}; //7.jiasushijian
unsigned char caidan_a1; //菜单状态0,1菜单位数1-6
unsigned char kaiguanji =1;
unsigned char wendushangxian =20;
unsigned char wenduxiaxian =10;
unsigned char shijian =1;
unsigned char jiaozheng=10;
unsigned char jiasushijian=10;
/**************************************************/
void main(void)
{
//unsigned char a1;
chushihua(); //初始化
/**************************************************/
while(1)
{
if(anjian)
{
led_h;
caidan_a1 ++; if(caidan_a1 ==8){caidan_a1 =1;}
caidan(); //菜单
chushihua(); //初始化
}
else{led_l;}
}
}
/**************************************************/
void chushihua() //初始化
{
//CLRWDT(); //关狗
/**************************************************/ //IO初始化
//PAIO &=~(1<<2); //0/1 输出/输入
//PAC |=(1<<2); //输出模式下:IO模式 0/1开漏/标准输出
//PAIO |=(1<<6); //0/1 输出/输入
//PAC |=(1<<6); //输入模式下:下拉电阻 1/0启用/禁用
PAIO |=1<<0; //1输入,按键PA0
PAC |=1<<0; //下拉电阻
PAIO &=~(1<<3); //PA3输出高
PAC |=(1<<3);
PA |=(1<<3);
PBIO &=~(1<<0); //led输出
PBC |=(1<<0);
PB &=~(1<<0);
PBIO &=0B00000011; //与lcd共用部分设为输出
PBC |=0B11111100; //输出模式下:IO模式 0/1开漏/标准输出
/**************************************************/ //LCD初始化
LCDPC =0;
LCDPC |=0b000 <<0; //[2:0]电荷泵时钟256HZ
//LCDPC |=0b001 <<0; //[2:0]电荷泵时钟512HZ
//LCDPC |=0b010 <<0; //[2:0]电荷泵时钟1KHZ
//LCDPC |=0b011 <<0; //[2:0]电荷泵时钟2KHZ
//LCDPC |=0b100 <<0; //[2:0]电荷泵时钟4KHZ
//LCDPC |=0b101 <<0; //[2:0]电荷泵时钟8KHZ
//LCDPC |=0b110 <<0; //[2:0]电荷泵时钟16KHZ
//LCDPC |=0b111 <<0; //[2:0]电荷泵时钟32KHZ
LCDPC |=0b1 <<3; //[3]电荷泵启用
LCDPC |=0b00 <<5; //[6:5]电压调节器1v
//LCDPC |=0b01 <<5; //[6:5]电压调节器1.17v
//LCDPC |=0b10 <<5; //[6:5]电压调节器1.33v
//LCDPC |=0b11 <<5; //[6:5]电压调节器1.5v
LCDPC |=0b1 <<4; //[4]内部电压调节器启用
LCDC =0;
LCDC |=0b100 <<0; //[2:0]128hz
LCDC |=0b01 <<3; //[4-3]打开LCD
//*(volatile unsigned char *)(0x200)= 0b00101000; //显示1234
//*(volatile unsigned char *)(0x208)= 0b10100110;
//*(volatile unsigned char *)(0x210)= 0b11101000;
//*(volatile unsigned char *)(0x218)= 0b10111110;
*(volatile unsigned char *)(0x200)= 0b01101000; //显示1234
*(volatile unsigned char *)(0x208)= 0b11111110;
*(volatile unsigned char *)(0x210)= 0b10100110;
*(volatile unsigned char *)(0x218)= 0b00101000;
yanshi(50); //延时
//while(1){}
/**************************************************/
}
/**************************************************/
void yanshi(unsigned char z1) //延时
{
unsigned char z2,z3;
for(z2=z1;z2>0;z2--)
for(z3=180;z3>0;z3--);
}
/**************************************************/
void xianshi() //显示
{
//ram位置__________________________________________
//|_0x200_|_4A_|_4F_|_3A_|_3F_|_2A_|_2F_|_1A_|_1F_| //高位....低位,xianshi_b1
//|_0x208_|_4B_|_4G_|_3B_|_3G_|_2B_|_2G_|_1B_|_1G_| //高位....低位,xianshi_b2
//|_0x210_|_4C_|_4E_|_3C_|_3E_|_2C_|_2E_|_1C_|_1E_| //高位....低位,xianshi_b3
//|_0x218_|_4D_|_4H_|_3D_|_3H_|_2D_|_2H_|_1D_|_1H_| //高位....低位,xianshi_b4
//unsigned char xianshi_a1; //全局变量
//unsigned char xianshi_a2;
//unsigned char xianshi_a3;
//unsigned char xianshi_a4;
unsigned char xianshi_b1 =0;
unsigned char xianshi_b2 =0;
unsigned char xianshi_b3 =0;
unsigned char xianshi_b4 =0;
if(xianshi_a1 &0b00000001) {xianshi_b1 |=0b00000010;} //1a //解码
if(xianshi_a1 &0b00000010) {xianshi_b2 |=0b00000010;} //1b
if(xianshi_a1 &0b00000100) {xianshi_b3 |=0b00000010;} //1c
if(xianshi_a1 &0b00001000) {xianshi_b4 |=0b00000010;} //1d
if(xianshi_a1 &0b00010000) {xianshi_b3 |=0b00000001;} //1e
if(xianshi_a1 &0b00100000) {xianshi_b1 |=0b00000001;} //1f
if(xianshi_a1 &0b01000000) {xianshi_b2 |=0b00000001;} //1g
if(xianshi_a1 &0b10000000) {xianshi_b4 |=0b00000001;} //1h
if(xianshi_a2 &0b00000001) {xianshi_b1 |=0b00001000;} //2a
if(xianshi_a2 &0b00000010) {xianshi_b2 |=0b00001000;} //2b
if(xianshi_a2 &0b00000100) {xianshi_b3 |=0b00001000;} //2c
if(xianshi_a2 &0b00001000) {xianshi_b4 |=0b00001000;} //2d
if(xianshi_a2 &0b00010000) {xianshi_b3 |=0b00000100;} //2e
if(xianshi_a2 &0b00100000) {xianshi_b1 |=0b00000100;} //2f
if(xianshi_a2 &0b01000000) {xianshi_b2 |=0b00000100;} //2g
if(xianshi_a2 &0b10000000) {xianshi_b4 |=0b00000100;} //2h
if(xianshi_a3 &0b00000001) {xianshi_b1 |=0b00100000;} //3a
if(xianshi_a3 &0b00000010) {xianshi_b2 |=0b00100000;} //3b
if(xianshi_a3 &0b00000100) {xianshi_b3 |=0b00100000;} //3c
if(xianshi_a3 &0b00001000) {xianshi_b4 |=0b00100000;} //3d
if(xianshi_a3 &0b00010000) {xianshi_b3 |=0b00010000;} //3e
if(xianshi_a3 &0b00100000) {xianshi_b1 |=0b00010000;} //3f
if(xianshi_a3 &0b01000000) {xianshi_b2 |=0b00010000;} //3g
if(xianshi_a3 &0b10000000) {xianshi_b4 |=0b00010000;} //3h
if(xianshi_a4 &0b00000001) {xianshi_b1 |=0b10000000;} //4a
if(xianshi_a4 &0b00000010) {xianshi_b2 |=0b10000000;} //4b
if(xianshi_a4 &0b00000100) {xianshi_b3 |=0b10000000;} //4c
if(xianshi_a4 &0b00001000) {xianshi_b4 |=0b10000000;} //4d
if(xianshi_a4 &0b00010000) {xianshi_b3 |=0b01000000;} //4e
if(xianshi_a4 &0b00100000) {xianshi_b1 |=0b01000000;} //4f
if(xianshi_a4 &0b01000000) {xianshi_b2 |=0b01000000;} //4g
if(xianshi_a4 &0b10000000) {xianshi_b4 |=0b01000000;} //4h
*(volatile unsigned char *)(0x200)= xianshi_b1; //放到指定位置
*(volatile unsigned char *)(0x208)= xianshi_b2;
*(volatile unsigned char *)(0x210)= xianshi_b3;
*(volatile unsigned char *)(0x218)= xianshi_b4;
}
/**************************************************/
void caidan() //菜单
{
unsigned char caidan_b1;
unsigned char caidan_b2;
if(caidan_a1 ==0){return;} //0退出
if(caidan_a1 ==1) //1-nihao,你好
{
for(caidan_b1 =1;caidan_b1 <caidan1[0];caidan_b1 ++) //取出菜单1的字模循环左移显示
{
caidan_b2 =caidan1[caidan_b1 +0]; //取元素位置
xianshi_a1 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan1[caidan_b1 +1]; //取元素位置
xianshi_a2 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan1[caidan_b1 +2]; //取元素位置
xianshi_a3 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan1[caidan_b1 +3]; //取元素位置
xianshi_a4 =zi1[caidan_b2]; //取元素
xianshi(); //显示译码
yanshi(100); //延时
}
//caidan_a1 =0; //结束菜单
return;
}
if(caidan_a1 ==2) //2-kaiguanji,开关机
{for(caidan_b1 =1;caidan_b1 <caidan2[0];caidan_b1 ++) //取出菜单2的字模循环左移显示
{
caidan_b2 =caidan2[caidan_b1 +0]; //取元素位置
xianshi_a1 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan2[caidan_b1 +1]; //取元素位置
xianshi_a2 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan2[caidan_b1 +2]; //取元素位置
xianshi_a3 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan2[caidan_b1 +3]; //取元素位置
xianshi_a4 =zi1[caidan_b2]; //取元素
xianshi(); //显示译码
yanshi(100); //延时
}
//caidan_a1 =0; //结束菜单
return;
}
if(caidan_a1 ==3) //3-wendushangxian,温度上限
{
for(caidan_b1 =1;caidan_b1 <caidan3[0];caidan_b1 ++) //取出菜单3的字模循环左移显示
{
caidan_b2 =caidan3[caidan_b1 +0]; //取元素位置
xianshi_a1 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan3[caidan_b1 +1]; //取元素位置
xianshi_a2 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan3[caidan_b1 +2]; //取元素位置
xianshi_a3 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan3[caidan_b1 +3]; //取元素位置
xianshi_a4 =zi1[caidan_b2]; //取元素
xianshi(); //显示译码
yanshi(100); //延时
}
//caidan_a1 =0; //结束菜单
return;
}
if(caidan_a1 ==4) //4-wenduxiaxian,温度下限
{
for(caidan_b1 =1;caidan_b1 <caidan4[0];caidan_b1 ++) //取出菜单1的字模循环左移显示
{
caidan_b2 =caidan4[caidan_b1 +0]; //取元素位置
xianshi_a1 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan4[caidan_b1 +1]; //取元素位置
xianshi_a2 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan4[caidan_b1 +2]; //取元素位置
xianshi_a3 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan4[caidan_b1 +3]; //取元素位置
xianshi_a4 =zi1[caidan_b2]; //取元素
xianshi(); //显示译码
yanshi(100); //延时
}
//caidan_a1 =0; //结束菜单
return;
}
if(caidan_a1 ==5) //5-shijian,时间
{
for(caidan_b1 =1;caidan_b1 <caidan5[0];caidan_b1 ++) //取出菜单1的字模循环左移显示
{
caidan_b2 =caidan5[caidan_b1 +0]; //取元素位置
xianshi_a1 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan5[caidan_b1 +1]; //取元素位置
xianshi_a2 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan5[caidan_b1 +2]; //取元素位置
xianshi_a3 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan5[caidan_b1 +3]; //取元素位置
xianshi_a4 =zi1[caidan_b2]; //取元素
xianshi(); //显示译码
yanshi(100); //延时
}
//caidan_a1 =0; //结束菜单
return;
}
if(caidan_a1 ==6) //6-jiaozheng,矫正
{
for(caidan_b1 =1;caidan_b1 <caidan6[0];caidan_b1 ++) //取出菜单1的字模循环左移显示
{
caidan_b2 =caidan6[caidan_b1 +0]; //取元素位置
xianshi_a1 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan6[caidan_b1 +1]; //取元素位置
xianshi_a2 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan6[caidan_b1 +2]; //取元素位置
xianshi_a3 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan6[caidan_b1 +3]; //取元素位置
xianshi_a4 =zi1[caidan_b2]; //取元素
xianshi(); //显示译码
yanshi(100); //延时
}
//caidan_a1 =0; //结束菜单
return;
}
if(caidan_a1 ==7) //7-jiasushijian,加速时间
{
for(caidan_b1 =1;caidan_b1 <caidan7[0];caidan_b1 ++) //取出菜单1的字模循环左移显示
{
caidan_b2 =caidan7[caidan_b1 +0]; //取元素位置
xianshi_a1 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan7[caidan_b1 +1]; //取元素位置
xianshi_a2 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan7[caidan_b1 +2]; //取元素位置
xianshi_a3 =zi1[caidan_b2]; //取元素
caidan_b2 =caidan7[caidan_b1 +3]; //取元素位置
xianshi_a4 =zi1[caidan_b2]; //取元素
xianshi(); //显示译码
yanshi(100); //延时
}
//caidan_a1 =0; //结束菜单
return;
}
}
/**************************************************/