{
//每0.5秒钟刷新重量 TL0 = 0x06;
TH0 = 0xf8; //定时器赋予初值
Counter ++; if (Counter >= 200) {
FlagTest = 1;
Counter = 0;
} }
//===============main program===================// void main(void) {
Rom_CS=1; initial_lcd(); EA = 0; Data_Init(); Port_Init(); Timer0_Init(); //初始化完成,开中断 EA = 1; //背光 LedA = 1;
clear_screen(); //clear all dots
display_GB2312_string(1,1,\电子秤初始化....\ To_Zero();
display_GB2312_string(1,1,\电子秤初始化成功\ display_GB2312_string(3,1,\重量: g\
while(1) {
//每0.5秒称重一次
if (FlagTest==1) {
//称重,得到重量值weight,单位为g
AdVal=ReadCount(); weight=FullScale-AdVal/1000; if (weight>0x8000) weight=0; weight=10000*weight/FullScale;
20
weight=weight*RATIO; //如果超量程,则报警 if (weight >= 10000) {
beep = 0; alert = 0;
display_GB2312_string(3,60,\display_GB2312_string(7,44,\
}
//如果不超量程 else {
beep = 1; alert = 1;
//显示重量值
Display_Weight();
//清测试标志
FlagTest = 0;
} }
//获取按键
keycode = Getkeyboard(); //有效键值0-15
if ((keycode<16)&&(FlagKeyPress==0)) {
FlagKeyPress = 1; KeyPress(keycode); FlagKeyPress = 0;
} delay(20);
} }
21
实物图:
22
23