?? debug.c
字號:
#include"DEBUG.H"
//////////////////////////////////////////////////////////////////////////////////////
///////////////延時函數///////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
void delay() //less than 1ms
{
uchar i;
for(i=0;i<100;i++)
_nop_();
}
void delay_160ms() //160ms
{
uchar i,j;
for(i=0;i<255;i++)
{
for(j=0;j<255;j++)
{
_nop_();
}
}
}
//延時500ms秒
void delay_500ms()
{
uchar i;
for(i=0;i<2;i++)
delay_160ms();
}
//延時1S
void delay_1s() //1s
{
uint i;
for(i=0;i<45000;i++)
{
_nop_();
_nop_();
}
}
////////////////////////////////////////////////////////////////////////////////////////
/////////////液晶相關函數//////////////////////////////////////e/////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
//write command to LCM//
void write_cmd( uchar cmdData)
{
uint idata i;
SID=1;
for(i=0;i<5;i++) //5個1
{
SCLK=0;SCLK=1;
}
SCLK=0;SID=0;SCLK=1; //RW
SCLK=0;SCLK=1; //RS
SCLK=0;SCLK=1; //0
SCLK=0;SID=cmdData&0x80;SCLK=1;
SCLK=0;SID=cmdData&0x40;SCLK=1;
SCLK=0;SID=cmdData&0x20;SCLK=1;
SCLK=0;SID=cmdData&0x10;SCLK=1;
SCLK=0;SID=0;SCLK=1; //四個0
SCLK=0;SCLK=1;
SCLK=0;SCLK=1;
SCLK=0;SCLK=1;
SCLK=0;SID=cmdData&0x08;SCLK=1;
SCLK=0;SID=cmdData&0x04;SCLK=1;
SCLK=0;SID=cmdData&0x02;SCLK=1;
SCLK=0;SID=cmdData&0x01;SCLK=1;
SCLK=0;SID=0;SCLK=1; //四個0
SCLK=0;SCLK=1;
SCLK=0;SCLK=1;
SCLK=0;SCLK=1;
SCLK=0;
delay();
}
//write data to LCD//
void write_data( char datData)
{
uint idata i;
SID=1; //五個 1
for(i=0;i<5;i++)
{
SCLK=0;SCLK=1;
}
SCLK=0;SID=0;SCLK=1; //RW
SCLK=0;SID=1;SCLK=1; //RS
SCLK=0;SID=0;SCLK=1;
SCLK=0;SID=datData&0x80;SCLK=1;
SCLK=0;SID=datData&0x40;SCLK=1;
SCLK=0;SID=datData&0x20;SCLK=1;
SCLK=0;SID=datData&0x10;SCLK=1;
SCLK=0;SID=0;SCLK=1;
SCLK=0;SCLK=1;
SCLK=0;SCLK=1;
SCLK=0;SCLK=1;
SCLK=0;SID=datData&0x08;SCLK=1;
SCLK=0;SID=datData&0x04;SCLK=1;
SCLK=0;SID=datData&0x02;SCLK=1;
SCLK=0;SID=datData&0x01;SCLK=1;
SCLK=0;SID=0;SCLK=1;
SCLK=0;SCLK=1;
SCLK=0;SCLK=1;
SCLK=0;SCLK=1;
SCLK=0;
//reset();
delay();
}
//液晶初始化函數
void init_LCD()
{
write_cmd(0x30); //功能設定:八位控制界面,基本指令集
write_cmd(0x0c); //顯示狀態開關:整體顯示
write_cmd(0x01); //清除顯示
write_cmd(0x06); //進入點設定:光標的移動方向(光標右移位址計數器加一)
write_cmd(0x01); //clear lcm screen
}
//print string to LCD///////
void put_string( uchar display_start_addr,char *str_source)
{
char idata i;
write_cmd(display_start_addr);
delay();
for( i=0;*str_source!='\0';i++)
{
write_data(*str_source);
delay();
str_source++;
}
}
//show vegetalbe type screen
void type_screen()
{
put_string(0x90," "); //顯示定位
switch(vege_page_index)
{
case 0:put_string(0x80,"01白蘿卜02菠菜 05大白菜06大蔥 03菜花 04長茄子");break;
case 1:put_string(0x80,"07大蒜 08冬瓜 11荷蘭豆12紅尖椒09豆角 10佛手 ");break;
case 2:put_string(0x80,"13胡蘿卜14黃豆芽17雞腿菇18尖椒 15黃瓜 16茴香 ");break;
case 3:put_string(0x80,"19茭白 20芥菜 23空心菜24苦瓜 21金針菇22韭菜 ");break;
case 4:put_string(0x80,"25蓮藕菜26綠豆芽29木耳 30南瓜 27綠尖椒28毛豆 ");break;
case 5:put_string(0x80,"31平菇 32茄子 35山藥 36生菜 33芹菜 34青椒 ");break;
case 6:put_string(0x80,"37生姜 38絲瓜 41茼蒿 42土豆 39蒜苗 40蒜薹 ");break;
case 7:put_string(0x80,"43萵筍 44西紅柿47西洋芹48香菜 45西葫蘆46西蘭花");break;
case 8:put_string(0x80,"49香椿 50香菇 53洋白菜54洋蔥頭51小白菜52小蔥 ");break;
case 9:put_string(0x80,"55油菜 56油麥菜 57圓茄子58竹筍 ");break;
default: break; //put_string(0x80,"page does not exist"); break;
}
put_string(0x98,"選擇代號:");
write_cmd(0x9d); //顯示地址設為第4行第6列
put_string(0x9d,vege_type) ; //顯示當前所選擇的蔬菜類型
}
//蔬菜價格界面顯示
void price_screen()
{
char idata a[3]={0xa3,0xaf,'\0'} ; ////////////中文字符'/'的中文字庫編碼
write_cmd(0x01); //全部清除顯示
put_string(0x90," "); //用于顯示定位,如果沒有這句就經常不會正常顯示
if(vege_type[0]=='0')
switch(vege_type[1])
{
case'1':put_string(0x90,"輸入白蘿卜價格:"); break;
case'2':put_string(0x90,"輸入菠菜價格:") ; break;
case'3':put_string(0x90,"輸入菜花價格:") ; break;
case'4':put_string(0x90,"輸入長茄子價格:"); break;
case'5':put_string(0x90,"輸入大白菜價格:"); break;
case'6':put_string(0x90,"輸入大蔥價格:") ; break;
case'7':put_string(0x90,"輸入大蒜價格:") ; break;
case'8':put_string(0x90,"輸入冬瓜價格:") ; break;
case'9':put_string(0x90,"輸入豆角價格:") ; break;
default: break;
}
else if(vege_type[0]=='1')
switch(vege_type[1])
{
case'0':put_string(0x90,"輸入佛手價格:") ; break;
case'1':put_string(0x90,"輸入荷蘭豆價格:"); break;
case'2':put_string(0x90,"輸入紅尖椒價格:"); break;
case'3':put_string(0x90,"輸入胡蘿卜價格:"); break;
case'4':put_string(0x90,"輸入黃豆牙價格:"); break;
case'5':put_string(0x90,"輸入黃瓜價格:") ; break;
case'6':put_string(0x90,"輸入茴香價格:") ; break;
case'7':put_string(0x90,"輸入雞腿菇價格:"); break;
case'8':put_string(0x90,"輸入尖椒價格:") ; break;
case'9':put_string(0x90,"輸入茭白價格:") ; break;
default: break;
}
else if(vege_type[0]=='2')
switch(vege_type[1])
{
case'0':put_string(0x90,"輸入芥菜價格:") ; break;
case'1':put_string(0x90,"輸入金針菇價格:"); break;
case'2':put_string(0x90,"輸入韭菜價格:") ; break;
case'3':put_string(0x90,"輸入空心菜價格:"); break;
case'4':put_string(0x90,"輸入苦瓜價格:") ; break;
case'5':put_string(0x90,"輸入蓮藕菜價格:"); break;
case'6':put_string(0x90,"輸入綠豆牙價格:"); break;
case'7':put_string(0x90,"輸入綠尖椒價格:"); break;
case'8':put_string(0x90,"輸入毛豆價格:") ; break;
case'9':put_string(0x90,"輸入木耳價格:") ; break;
default: break;
}
else if(vege_type[0]=='3')
switch(vege_type[1])
{
case'0':put_string(0x90,"輸入南瓜價格:"); break;
case'1':put_string(0x90,"輸入平菇價格:"); break;
case'2':put_string(0x90,"輸入茄子價格:"); break;
case'3':put_string(0x90,"輸入芹菜價格:"); break;
case'4':put_string(0x90,"輸入青椒價格:"); break;
case'5':put_string(0x90,"輸入山藥價格:"); break;
case'6':put_string(0x90,"輸入生菜價格:"); break;
case'7':put_string(0x90,"輸入生姜價格:"); break;
case'8':put_string(0x90,"輸入絲瓜價格:"); break;
case'9':put_string(0x90,"輸入蒜苗價格:"); break;
default: break;
}
else if(vege_type[0]=='4')
switch(vege_type[1])
{
case'0':put_string(0x90,"輸入蒜薹價格:") ; break;
case'1':put_string(0x90,"輸入茼蒿價格:") ; break;
case'2':put_string(0x90,"輸入土豆價格:") ; break;
case'3':put_string(0x90,"輸入萵筍價格:") ; break;
case'4':put_string(0x90,"輸入西紅柿價格:"); break;
case'5':put_string(0x90,"輸入西葫蘆價格:"); break;
case'6':put_string(0x90,"輸入西蘭花價格:"); break;
case'7':put_string(0x90,"輸入西洋芹價格:"); break;
case'8':put_string(0x90,"輸入香菜價格:") ; break;
case'9':put_string(0x90,"輸入香椿價格:") ; break;
default: break;
}
else if(vege_type[0]=='5')
switch(vege_type[1])
{
case'0':put_string(0x90,"輸入香菇價格:") ; break;
case'1':put_string(0x90,"輸入小白菜價格:"); break;
case'2':put_string(0x90,"輸入小蔥價格:") ; break;
case'3':put_string(0x90,"輸入洋白菜價格:"); break;
case'4':put_string(0x90,"輸入洋蔥頭價格:"); break;
case'5':put_string(0x90,"輸入油菜價格:") ; break;
case'6':put_string(0x90,"輸入油麥菜價格:"); break;
case'7':put_string(0x90,"輸入圓茄子價格:"); break;
case'8':put_string(0x90,"輸入竹筍價格:") ; break;
default: break;
}
write_cmd(0x9a);
put_string(0x9a,"(元 公斤)");
put_string(0x9c,a); ////第4行第5列顯示中文字符'/'
}
//顯示己存信息
void info_screen()
{
char idata i;
write_cmd(0x01); //清除當前顯示
put_string(0x80," ");
put_string(0x80,"發送以下信息嗎?");
// receive_SMS(); //receive SMS,judge the center_phone change
for(i=info_page_index*3; (i<info_page_index*3+3)&&(i<info_count);i++)
put_string(0x88+8*(i-info_page_index*3),info_string(i)) ;
}
//返回第x條信息對應的字符串
char *info_string(char x)
{
char idata i ,j=-1 ,info[8], type[9]; //, price[6];
static char idata total[17];
//讀取第x條蔬菜信息存到info[]數組
for(i=0;i<strlen(sms_deliver.PDUData);i++)
{
if(sms_deliver.PDUData[i]==',')
j++;
if(j==x)
break;
}
i++; //i為第x條信息的第一個字符的索引號
j=0;
while(sms_deliver.PDUData[i]!=','&&sms_deliver.PDUData[i]!='\0')
{
info[j]=sms_deliver.PDUData[i];
j++; i++;
}
info[j]='\0';
if(info[0]=='0')
switch(info[1])
{
case'1':strcpy(type,"白蘿卜:") ; break;
case'2':strcpy(type,"菠菜: ") ; break;
case'3':strcpy(type,"菜花: ") ; break;
case'4':strcpy(type,"長茄子:") ; break;
case'5':strcpy(type,"大白菜:") ; break;
case'6':strcpy(type,"大蔥: ") ; break;
case'7':strcpy(type,"大蒜: ") ; break;
case'8':strcpy(type,"冬瓜: ") ; break;
case'9':strcpy(type,"豆角: ") ; break;
default: break;
}
else if(info[0]=='1')
switch(info[1])
{
case'0':strcpy(type,"佛手: ") ; break;
case'1':strcpy(type,"荷蘭豆:") ; break;
case'2':strcpy(type,"紅尖椒:") ; break;
case'3':strcpy(type,"胡蘿卜:") ; break;
case'4':strcpy(type,"黃豆牙:") ; break;
case'5':strcpy(type,"黃瓜: ") ; break;
case'6':strcpy(type,"茴香: ") ; break;
case'7':strcpy(type,"雞腿菇:") ; break;
case'8':strcpy(type,"尖椒: ") ; break;
case'9':strcpy(type,"茭白: ") ; break;
default: break;
}
else if(info[0]=='2')
switch(info[1])
{
case'0':strcpy(type,"芥菜: ") ; break;
case'1':strcpy(type,"金針菇:") ; break;
case'2':strcpy(type,"韭菜: ") ; break;
case'3':strcpy(type,"空心菜:") ; break;
case'4':strcpy(type,"苦瓜: ") ; break;
case'5':strcpy(type,"蓮藕菜:") ; break;
case'6':strcpy(type,"綠豆牙:") ; break;
case'7':strcpy(type,"綠尖椒:") ; break;
case'8':strcpy(type,"毛豆: ") ; break;
case'9':strcpy(type,"木耳: ") ; break;
default: break;
}
else if(info[0]=='3')
switch(info[1])
{
case'0':strcpy(type,"南瓜: "); break;
case'1':strcpy(type,"平菇: "); break;
case'2':strcpy(type,"茄子: "); break;
case'3':strcpy(type,"芹菜: "); break;
case'4':strcpy(type,"青椒: "); break;
case'5':strcpy(type,"山藥: "); break;
case'6':strcpy(type,"生菜: "); break;
case'7':strcpy(type,"生姜: "); break;
case'8':strcpy(type,"絲瓜: "); break;
case'9':strcpy(type,"蒜苗: "); break;
default: break;
}
else if(info[0]=='4')
switch(info[1])
{
case'0':strcpy(type,"蒜薹: ") ; break;
case'1':strcpy(type,"茼蒿: ") ; break;
case'2':strcpy(type,"土豆: ") ; break;
case'3':strcpy(type,"萵筍: ") ; break;
case'4':strcpy(type,"西紅柿:") ; break;
case'5':strcpy(type,"西葫蘆:") ; break;
case'6':strcpy(type,"西蘭花:") ; break;
case'7':strcpy(type,"西洋芹:") ; break;
case'8':strcpy(type,"香菜: ") ; break;
case'9':strcpy(type,"香椿: ") ; break;
default: break;
}
else if(info[0]=='5')
switch(info[1])
{
case'0':strcpy(type,"香菇: ") ; break;
case'1':strcpy(type,"小白菜:") ; break;
case'2':strcpy(type,"小蔥: ") ; break;
case'3':strcpy(type,"洋白菜:") ; break;
case'4':strcpy(type,"洋蔥頭:") ; break;
case'5':strcpy(type,"油菜: ") ; break;
case'6':strcpy(type,"油麥菜:") ; break;
case'7':strcpy(type,"圓茄子:") ; break;
case'8':strcpy(type,"竹筍: ") ; break;
default: break;
}
strcpy(total,type);
total[8]=' ';
//拷貝蔬菜價格到數組total[]中
for(j=2;j<strlen(info);j++)
total[7+j]=info[j];
for(j+=7; j<14; j++ )
total[j]=' '; //空余的數組字節置空格
total[14]=0xd4; total[15]=0xaa; //'元'的中文字庫碼為0xd4aa
total[16]='\0';
return(total);
}
///////////////////////////////////////////////////////////////////////////////////////
/////////////按鍵相關函數//////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
//數字鍵的響應函數
void key_num(char x)
{
char c=0x30+x; //數字x轉換成ASC字符
if(display_type==0) //蔬菜品種界面
{
if(vege_type[0]=='\0'&&vege_type[1]=='\0') //尚未設定蔬菜品種
vege_type[0]=c; //把x變換成字符保存到蔬菜品種第0位
else if(vege_type[0]!='\0'&&vege_type[1]=='\0')
vege_type[1]=c; //保存到第1位
put_string(0x9d,vege_type); // 在第4行第6列處顯示蔬菜種類代號
return;
}
if(display_type==1)
{
if(vege_price[0]=='\0') vege_price[0]=c; //保存蔬菜價格
else if(vege_price[1]=='\0') vege_price[1]=c;
else if(vege_price[1]=='.'&&vege_price[2]=='\0') vege_price[2]=c;
else if( (vege_price[1]=='.'||vege_price[2]=='.')&&vege_price[3]=='\0' ) vege_price[3]=c;
else if(vege_price[2]=='.'&&vege_price[4]=='\0') vege_price[4]=c;
vege_price[5]='\0';
put_string(0x8a,vege_price); //顯示輸入的價格
}
}
// . 鍵的響應函數
void key_dot()
{
if(display_type==1)
if(vege_price[0]!='\0')
if(vege_price[1]!='.'&&vege_price[2]!='.')
{
if(vege_price[1]=='\0') vege_price[1]='.';
else if(vege_price[2]=='\0') vege_price[2]='.' ;
put_string(0x8a,vege_price); //顯示價格
}
return;
}
//取消鍵的響應函數
void key_cancel()
{
uchar idata i ;
char chu[3]={0xb3,0xfd,'\0'}; //'除'字的中文字庫為0xB3FD
if(display_type==0)
{
if(vege_type[1]!='\0')
vege_type[1]='\0';
else if(vege_type[0]!='\0')
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -