/***************SC92F7323+LCD88888*****************/
/***************QQ:74145445************************/
/*************快手:共同学习STM8********************/
/*************keiluvision2*************************/
/*************20210808*****************************/
/*************6MHZ@25HZ,3.3V,LVR2.9V***************/
// __________________lcd88888____________________
// | |
// | _ _ _ _ |
// | | | | | ℃ | | | | ℃ |
// | |_| |_| |_| |_| _ |
// | | | | | | | | | |_| |
// | |_| |_| |_| |_| |_| |
// | |
// |______________________________________________|
// |1|2|3|4|5|6|7|8|9|10|11|12|com4|com3|com2|com1|
// ----------------------------------------------
/**************************************************/
// SC92F7323
// ________ ________
// 5V-|1 /VDD \_/ P0.0/28|-com1
// 0V-|2 /VSS P0.1/27|-com2
// -|3 /P5.1 P0.2/26|-com3
// -|4 /P5.0 P0.3/25|-com4
// -|5 /P1.0 P0.4/24|-lcd_1
// -|6 /P1.1 P0.5/23|-lcd_2
// TCK-|7 /P1.2 P0.6/22|-lcd_3
// TDIO-|8 /P1.3 P0.7/21|-lcd_4
// beiguang-|9 /P1.4 P2.0/20|-lcd_5
// -|10/P1.5 P2.1/19|-lcd_6
// -|11/P1.6 P2.2/18|-lcd_7
// ntc_neibu-|12/P1.7 P2.3/17|-lcd_8
// lcd_12-|13/P2.7 P2.4/16|-lcd_9
// lcd_11-|14/P2.6_____P2.5/15|-lcd_10
/**************************************************/
#include <SC92F732x_C.H>
/**************************************************/ //lcd
sbit lcd_1 =P0^4;
sbit lcd_2 =P0^5;
sbit lcd_3 =P0^6;
sbit lcd_4 =P0^7;
sbit lcd_5 =P2^0;
sbit lcd_6 =P2^1;
sbit lcd_7 =P2^2;
sbit lcd_8 =P2^3;
sbit lcd_9 =P2^4;
sbit lcd_10 =P2^5;
sbit lcd_11 =P2^6;
sbit lcd_12 =P2^7;
sbit beiguang =P1^4;
unsigned char lcd_a1; //第一位
unsigned char lcd_a2; //第二位
unsigned char lcd_a3; //第三位
unsigned char lcd_a4; //第四位
unsigned char lcd_a5; //第五位
unsigned char xs_a1; //显示用
unsigned char xs_a2;
unsigned char xs_a3;
unsigned char xs_a4;
char temp_a1; //温度整数(有时是负数)
unsigned char temp_a2; //温度小数
//unsigned char wendu; //设定温度
unsigned char code biao[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d, //0-f,16-,17E,18r字模
0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40,0x79,0x50};
/**************************************************/
#define bit0 0x01
#define bit1 0x02
#define bit2 0x04
#define bit3 0x08
#define bit4 0x10
#define bit5 0x20
#define bit6 0x40
#define bit7 0x80
#define com1_gao P0VO &= ~bit0; P00=1
#define com1_ban P0VO |=bit0
#define com1_di P0VO &= ~bit0; P00=0
#define com2_gao P0VO &= ~bit1; P01=1
#define com2_ban P0VO |=bit1
#define com2_di P0VO &= ~bit1; P01=0
#define com3_gao P0VO &= ~bit2; P02=1
#define com3_ban P0VO |=bit2
#define com3_di P0VO &= ~bit2; P02=0
#define com4_gao P0VO &= ~bit3; P03=1
#define com4_ban P0VO |=bit3
#define com4_di P0VO &= ~bit3; P03=0
#define adc_start ADCCON |=bit6
//ADC启动
#define adc_eoc ADCCON &bit4
//ADC结束标志位(1完成)
/**************************************************/
void lcd_jisuan(); //lcd计算
void lcd_xianshi(); //lcd显示
void ntc_neibu(); //ntc内部(ad通道8)
void wendu_jisuan(); //温度计算
void yanshi(); //延时
/**************************************************/
void main()
{
//unsigned char a1;
/**************************************************/
xs_a1 =0;
xs_a2 =0;
xs_a3 =0;
xs_a4 =0;
/**************************************************/ //液晶初始化
P0CON |=bit0|bit1|bit2|bit3|bit4|bit5|bit6|bit7; //输出模式
P2CON |=bit0|bit1|bit2|bit3|bit4|bit5|bit6|bit7;
OTCON =bit3|bit2; //分压电阻87.5k
P1CON |=bit4; //背光输出
beiguang =0;
/************************************************** //ad初始化
//#define adc_start ADCCON |=bit6
//启动ADC
//#define adc_eoc ADCCON &bit4
//ADC结束标志位(1完成)
ADCCON |=bit7; //ADC电源
//ADCCON |=bit6; //启动ADC
ADCCON &=~bit5; //采样时钟2MHz
//ADCCON&bit4 //转换完成
ADCCON |=bit3; //1000,AIN8
ADCCON &=~bit2;
ADCCON &=~bit1;
ADCCON &=~bit0;
//ADCCON |=bit3; //1001,AIN9
//ADCCON &=~(bit2|bit1);
//ADCCON |=bit0;
ADCCFG0 =0; //设AIN8为ADC输入
ADCCFG1 |=bit0;
ADCCFG1 &=~bit1;
//sfr OPREG = 0XFF; //参考电压
//OPREG &=~bit7; //vdd
OPREG |=bit7; //2.4v
//ADCVL //低四位
//ADCVH //高八位
/**************************************************/
while(1)
{
xs_a1 ++;
if(xs_a1==25)
{
xs_a1 =0;
ntc_neibu();
wendu_jisuan();
lcd_jisuan();
xs_a2 ++;
}
lcd_xianshi();
}
}
void lcd_xianshi() //lcd显示
{
/**************************************************/ //lcd正控
com1_ban;
com2_ban;
com3_ban;
com4_ban;
if(lcd_a1 & bit5) {lcd_1 =0;} else{lcd_1 =1;} //1f
if(lcd_a1 & bit0) {lcd_2 =0;} else{lcd_2 =1;} //1a
if(lcd_a2 & bit5) {lcd_3 =0;} else{lcd_3 =1;} //2f
if(lcd_a2 & bit0) {lcd_4 =0;} else{lcd_4 =1;} //2a
//if(lcd_xianshi) {lcd_5 =0;} else{lcd_5 =1;} //02竖(显示)
lcd_5 =0;
if(lcd_a3 & bit5) {lcd_6 =0;} else{lcd_6 =1;} //3f
if(lcd_a3 & bit0) {lcd_7 =0;} else{lcd_7 =1;} //3a
if(lcd_a4 & bit5) {lcd_8 =0;} else{lcd_8 =1;} //4f
if(lcd_a4 & bit0) {lcd_9 =0;} else{lcd_9 =1;} //4a
if(lcd_a5 & bit5) {lcd_10 =0;} else{lcd_10 =1;} //5f
if(lcd_a5 & bit0) {lcd_11 =0;} else{lcd_11 =1;} //5a
//if(lcd_a) {lcd_12 =0;} else{lcd_12 =1;} //01锁定
lcd_12 =1;
com1_gao; //com1高
com2_ban;
com3_ban;
com4_ban;
yanshi();
com1_ban;
com2_ban;
com3_ban;
com4_ban;
if(lcd_a1 & bit6) {lcd_1 =0;} else{lcd_1 =1;} //1g
if(lcd_a1 & bit1) {lcd_2 =0;} else{lcd_2 =1;} //1b
if(lcd_a2 & bit6) {lcd_3 =0;} else{lcd_3 =1;} //2g
if(lcd_a2 & bit1) {lcd_4 =0;} else{lcd_4 =1;} //2b
//if(lcd_a) {lcd_5 =0;} else{lcd_5 =1;} //防冻
lcd_5 =1;
if(lcd_a3 & bit6) {lcd_6 =0;} else{lcd_6 =1;} //3g
if(lcd_a3 & bit1) {lcd_7 =0;} else{lcd_7 =1;} //3b
if(lcd_a4 & bit6) {lcd_8 =0;} else{lcd_8 =1;} //4g
if(lcd_a4 & bit1) {lcd_9 =0;} else{lcd_9 =1;} //4b
if(lcd_a5 & bit6) {lcd_10 =0;} else{lcd_10 =1;} //5g
if(lcd_a5 & bit1) {lcd_11 =0;} else{lcd_11 =1;} //5b
//if(lcd_a) {lcd_12 =0;} else{lcd_12 =1;} //中
lcd_12 =1;
com1_ban;
com2_gao; //com2高
com3_ban;
com4_ban;
yanshi();
com1_ban;
com2_ban;
com3_ban;
com4_ban;
if(lcd_a1 & bit4) {lcd_1 =0;} else{lcd_1 =1;} //1e
if(lcd_a1 & bit2) {lcd_2 =0;} else{lcd_2 =1;} //1c
if(lcd_a2 & bit4) {lcd_3 =0;} else{lcd_3 =1;} //2e
if(lcd_a2 & bit2) {lcd_4 =0;} else{lcd_4 =1;} //2c
//if(lcd_a) {lcd_5 =0;} else{lcd_5 =1;} //保护
lcd_5 =1;
if(lcd_a3 & bit4) {lcd_6 =0;} else{lcd_6 =1;} //3e
if(lcd_a3 & bit2) {lcd_7 =0;} else{lcd_7 =1;} //3c
if(lcd_a4 & bit4) {lcd_8 =0;} else{lcd_8 =1;} //4e
if(lcd_a4 & bit2) {lcd_9 =0;} else{lcd_9 =1;} //4c
if(lcd_a5 & bit4) {lcd_10 =0;} else{lcd_10 =1;} //5e
if(lcd_a5 & bit2) {lcd_11 =0;} else{lcd_11 =1;} //5c
//if(lcd_a) {lcd_12 =0;} else{lcd_12 =1;} //加热
lcd_12 =1;
com1_ban;
com2_ban;
com3_gao; //com3高
com4_ban;
yanshi();
com1_ban;
com2_ban;
com3_ban;
com4_ban;
//if(lcd_a) {lcd_1 =0;} else{lcd_1 =1;} //室温
lcd_1 =1;
if(lcd_a1 & bit3) {lcd_2 =0;} else{lcd_2 =1;} //1d
//if(lcd_a) {lcd_3 =0;} else{lcd_3 =1;} //设定摄氏度(显示)
lcd_3 =0;
if(lcd_a2 & bit3) {lcd_4 =0;} else{lcd_4 =1;} //2d
//if(lcd_a){lcd_5 =0;} else{lcd_5 =1;} //无
lcd_5 =1;
//if(lcd_a) {lcd_6 =0;} else{lcd_6 =1;} //地温
lcd_6 =1;
if(lcd_a3 & bit3) {lcd_7 =0;} else{lcd_7 =1;} //3d
//if(lcd_a) {lcd_8 =0;} else{lcd_8 =1;} //℃(显示)
lcd_8 =0;
if(lcd_a4 & bit3) {lcd_9 =0;} else{lcd_9 =1;} //4d
//if(lcd_a) {lcd_10 =0;} else{lcd_10 =1;} //点(显示)
lcd_10 =0;
if(lcd_a5 & bit3) {lcd_11 =0;} else{lcd_11 =1;} //5d
//if(lcd_a) {lcd_12 =0;} else{lcd_12 =1;} //停止
lcd_12 =1;
com1_ban;
com2_ban;
com3_ban;
com4_gao; //com4高
yanshi();
/**************************************************/ //lcd反控
com1_ban;
com2_ban;
com3_ban;
com4_ban;
if(lcd_a1 & bit5) {lcd_1 =1;} else{lcd_1 =0;} //1f
if(lcd_a1 & bit0) {lcd_2 =1;} else{lcd_2 =0;} //1a
if(lcd_a2 & bit5) {lcd_3 =1;} else{lcd_3 =0;} //2f
if(lcd_a2 & bit0) {lcd_4 =1;} else{lcd_4 =0;} //2a
//if(lcd_a2){lcd_5 =1;} else{lcd_5 =0;} //02竖(显示)
lcd_5 =1;
if(lcd_a3 & bit5) {lcd_6 =1;} else{lcd_6 =0;} //3f
if(lcd_a3 & bit0) {lcd_7 =1;} else{lcd_7 =0;} //3a
if(lcd_a4 & bit5) {lcd_8 =1;} else{lcd_8 =0;} //4f
if(lcd_a4 & bit0) {lcd_9 =1;} else{lcd_9 =0;} //4a
if(lcd_a5 & bit5) {lcd_10 =1;} else{lcd_10 =0;} //5f
if(lcd_a5 & bit0) {lcd_11 =1;} else{lcd_11 =0;} //5a
//if(lcd_a) {lcd_12 =1;} else{lcd_12 =0;} //01锁定
lcd_12 =0;
com1_di; //com1低
com2_ban;
com3_ban;
com4_ban;
yanshi();
com1_ban;
com2_ban;
com3_ban;
com4_ban;
if(lcd_a1 & bit6) {lcd_1 =1;} else{lcd_1 =0;} //1g
if(lcd_a1 & bit1) {lcd_2 =1;} else{lcd_2 =0;} //1b
if(lcd_a2 & bit6) {lcd_3 =1;} else{lcd_3 =0;} //2g
if(lcd_a2 & bit1) {lcd_4 =1;} else{lcd_4 =0;} //2b
//if(lcd_a) {lcd_5 =1;} else{lcd_5 =0;} //防冻
lcd_5 =0;
if(lcd_a3 & bit6) {lcd_6 =1;} else{lcd_6 =0;} //3g
if(lcd_a3 & bit1) {lcd_7 =1;} else{lcd_7 =0;} //3b
if(lcd_a4 & bit6) {lcd_8 =1;} else{lcd_8 =0;} //4g
if(lcd_a4 & bit1) {lcd_9 =1;} else{lcd_9 =0;} //4b
if(lcd_a5 & bit6) {lcd_10 =1;} else{lcd_10 =0;} //5g
if(lcd_a5 & bit1) {lcd_11 =1;} else{lcd_11 =0;} //5b
//if(lcd_a) {lcd_12 =1;} else{lcd_12 =0;} //中
lcd_12 =0;
com1_ban;
com2_di; //com2低
com3_ban;
com4_ban;
yanshi();
com1_ban;
com2_ban;
com3_ban;
com4_ban;
if(lcd_a1 & bit4) {lcd_1 =1;} else{lcd_1 =0;} //1e
if(lcd_a1 & bit2) {lcd_2 =1;} else{lcd_2 =0;} //1c
if(lcd_a2 & bit4) {lcd_3 =1;} else{lcd_3 =0;} //2e
if(lcd_a2 & bit2) {lcd_4 =1;} else{lcd_4 =0;} //2c
//if(lcd_a) {lcd_5 =1;} else{lcd_5 =0;} //保护
lcd_5 =0;
if(lcd_a3 & bit4) {lcd_6 =1;} else{lcd_6 =0;} //3e
if(lcd_a3 & bit2) {lcd_7 =1;} else{lcd_7 =0;} //3c
if(lcd_a4 & bit4) {lcd_8 =1;} else{lcd_8 =0;} //4e
if(lcd_a4 & bit2) {lcd_9 =1;} else{lcd_9 =0;} //4c
if(lcd_a5 & bit4) {lcd_10 =1;} else{lcd_10 =0;} //5e
if(lcd_a5 & bit2) {lcd_11 =1;} else{lcd_11 =0;} //5c
//if(lcd_a) {lcd_12 =1;} else{lcd_12 =0;} //加热
lcd_12 =0;
com1_ban;
com2_ban;
com3_di; //com3低
com4_ban;
yanshi();
com1_ban;
com2_ban;
com3_ban;
com4_ban;
//if(lcd_a) {lcd_1 =1;} else{lcd_1 =0;} //室温
lcd_1 =0;
if(lcd_a1 & bit3) {lcd_2 =1;} else{lcd_2 =0;} //1d
//if(lcd_a) {lcd_3 =1;} else{lcd_3 =0;} //设定摄氏度(显示)
lcd_3 =1;
if(lcd_a2 & bit3) {lcd_4 =1;} else{lcd_4 =0;} //2d
//if(lcd_a) {lcd_5 =1;} else{lcd_5 =0;} //无
lcd_5 =0;
//if(lcd_a) {lcd_6 =1;} else{lcd_6 =0;} //地温
lcd_6 =0;
if(lcd_a3 & bit3) {lcd_7 =1;} else{lcd_7 =0;} //3d
//if(lcd_a) {lcd_8 =1;} else{lcd_8 =0;} //℃(显示)
lcd_8 =1;
if(lcd_a4 & bit3) {lcd_9 =1;} else{lcd_9 =0;} //4d
//if(lcd_a) {lcd_10 =1;} else{lcd_10 =0;} //点(显示)
lcd_10 =1;
if(lcd_a5 & bit3) {lcd_11 =1;} else{lcd_11 =0;} //5d
//if(lcd_a) {lcd_12 =1;} else{lcd_12 =0;} //停止
lcd_12 =0;
com1_ban;
com2_ban;
com3_ban;
com4_di; //com4低
yanshi();
}
/**************************************************/ //温度计算
// ________ 2.4V---|\___ADC
// |--|__100R__|-------|/
// ________ |
//5v--|_ntc10k_|-| _________
// |-|__R5.1k__|---GND
// ____________________________________
//|_℃_|___ad__|___0b_|__差_|_1℃__*10_|
//|-10_|_0x157_|__343_|_212_|_2.1_|_21_|
//|__0_|_0x22b_|__555_|_276_|_2.8_|_28_|
//|_10_|_0x33f_|__831_|_348_|_3.5_|_35_|
//|_20_|_0x49b_|_1179_|_408_|__4__|_40_|
//|_30_|_0x633_|_1587_|_418_|_4.1_|_41_|
//|_40_|_0x7d5_|_2005_|_400_|__4__|_40_|
//|_50_|_0x965_|_2405_|_355_|_3.5_|_35_|
//|_60_|_0xac8_|_2760_|_312_|_3.1_|_31_|
//|_70_|_0xc00_|_3072_|_233_|_2.3_|_23_|
//|_80_|_0xce9_|_3305_|_178_|_1.8_|_18_|
//|_90_|_0xd9b_|_3483_|_144_|_1.4_|_14_|
//|100_|_0xe2b_|_3627_|_104_|__1__|_10_|
//|110_|_0xe93_|_3731_|_____|_____|____|
/**************************************************/
void wendu_jisuan() //温度计算
{
unsigned int js_a1;
temp_a1 =0; //温度整数
temp_a2 =0; //温度小数
js_a1 =0;
//ntc_neibu(); //切换到内部ntc(ad通道8)
//adc_start; //启动ADC
//while(!adc_eoc){;;} //等待转换完成
js_a1 =ADCVH;
js_a1 <<=4;
js_a1 |=ADCVL>>4;
if(js_a1 <343) //小于-10无法显示
{temp_a1 =-10;}
if(js_a1 <555) //-1--9℃,每度2.1
{
js_a1 -=343;
js_a1 *=10; //放大10倍
temp_a1 =js_a1/210; //整数
temp_a1 =~temp_a1; //取反变负数
temp_a2 =(js_a1%210)/21; //小数
return;
}
if(js_a1 <831) //0-9.9℃,每度2.8
{
js_a1 -=555;
js_a1 *=10; //放大10倍
temp_a1 =js_a1/280; //整数
temp_a1 +=0; //补偿
temp_a2 =(js_a1%280)/28; //小数
return;
}
if(js_a1 <1179) //10-19.9℃,每度3.5
{
js_a1 -=831;
js_a1 *=10; //放大10倍
temp_a1 =js_a1/350; //整数
temp_a1 +=10; //补偿
temp_a2 =(js_a1%350)/35; //小数
return;
}
if(js_a1 <1587) //20-29.9℃,每度4
{
js_a1 -=1179;
js_a1 *=10; //放大10倍
temp_a1 =js_a1/400; //整数
temp_a1 +=20; //补偿
temp_a2 =(js_a1%400)/40; //小数
return;
}
if(js_a1 <2005) //30-39.9℃,每度4.1
{
js_a1 -=1587;
js_a1 *=10; //放大10倍
temp_a1 =js_a1/410; //整数
temp_a1 +=30; //补偿
temp_a2 =(js_a1%410)/41; //小数
return;
}
if(js_a1 <2405) //40-49.9℃,每度4
{
js_a1 -=2005;
js_a1 *=10; //放大10倍
temp_a1 =js_a1/400; //整数
temp_a1 +=40; //补偿
temp_a2 =(js_a1%400)/40; //小数
return;
}
if(js_a1 <2760) //50-59.9℃,每度3.5
{
js_a1 -=2405;
js_a1 *=10; //放大10倍
temp_a1 =js_a1/350; //整数
temp_a1 +=50; //补偿
temp_a2 =(js_a1%350)/35; //小数
return;
}
if(js_a1 <3072) //60-69.9℃,每度3.1
{
js_a1 -=2760;
js_a1 *=10; //放大10倍
temp_a1 =js_a1/310; //整数
temp_a1 +=60; //补偿
temp_a2 =(js_a1%310)/31; //小数
return;
}
if(js_a1 <3305) //70-79.9℃,每度2.3
{
js_a1 -=3072;
js_a1 *=10; //放大10倍
temp_a1 =js_a1/230; //整数
temp_a1 +=70; //补偿
temp_a2 =(js_a1%230)/23; //小数
return;
}
if(js_a1 <3483) //80-89.9℃,每度1.8
{
js_a1 -=3305;
js_a1 *=10; //放大10倍
temp_a1 =js_a1/180; //整数
temp_a1 +=80; //补偿
temp_a2 =(js_a1%180)/18; //小数
return;
}
if(js_a1 <3627) //90-99.9℃,每度1.4
{
js_a1 -=3483;
js_a1 *=10; //放大10倍
temp_a1 =js_a1/140; //整数
temp_a1 +=90; //补偿
temp_a2 =(js_a1%140)/14; //小数
return;
}
if(js_a1 >=3627) //大于100℃无法显示
{
temp_a1 =100;
temp_a2 =0;
}
}
/**************************************************/ //内部ntc
void ntc_neibu() //ntc内部(ad通道8)
{
ADCCON =bit7+bit3;
ADCCFG0 =0;
ADCCFG1 =bit0;
//sfr OPREG = 0XFF; //参考电压
OPREG |=bit7; //参考电压2.4v
adc_start; //启动ADC
while(!adc_eoc){;;} //等待转换完成
}
/**************************************************/
void lcd_jisuan() //lcd计算
{
lcd_a1 =biao[xs_a2 >>4];
lcd_a2 =biao[xs_a2 &0x0f];
if(temp_a1<0) //0℃以下
{
if(temp_a1<-9) //-9℃以下显示-Er
{
lcd_a3 =biao[16];
lcd_a4 =biao[17];
lcd_a5 =biao[18];
return;
}
lcd_a3 =biao[16]; //-号
lcd_a4 =biao[~temp_a1];
lcd_a5 =biao[temp_a2];
return;
}
if(temp_a1 >99) //100℃以上显示Err
{
lcd_a3 =biao[17];
lcd_a4 =biao[18];
lcd_a5 =biao[18];
return;
}
lcd_a3 =biao[temp_a1/10];
lcd_a4 =biao[temp_a1%10];
lcd_a5 =biao[temp_a2];
}
/**************************************************/
void yanshi() //延时
{
unsigned char x,y;
for(x=100;x>0;x--)
for(y=60;y>0;y--);
}
/**************************************************/
/**************************************************/
/**************************************************/
/**************************************************/
/**************************************************/
|