⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug.c

📁 51单片机C语言常用模块与综合系统设计实例精讲
💻 C
字号:
#include <stdio.h>
#include <./Atmel/at89x52.h>
#include <absacc.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include  "source.h"
extern void SD2000_read_hour(struct RTC_TIME *p);
unsigned char  flash_wbuf[8]={0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa};
unsigned char  flash_rbuf[8]={0,0,0,0,0,0,0,0};
#define MAX_DB_ARGC  5
#define DBCMD_LEN 20
#define PROMPT     "\nLandMore>."
unsigned char dbcmd[MAX_DB_ARGC+2][DBCMD_LEN];
unsigned char dbcmd_len=0;
unsigned char argc=0;
unsigned int intnum;
unsigned char charnum;
unsigned char ch;
unsigned int eeprom_dbgadd;
union SFADD dwn_add_debug;
bit space_flag=1;
unsigned char error_flag=0;
bit debug(void){	
	unsigned char i;
	if(dsr_tail!=dsr_head){		
		if(dsr_buf[dsr_tail]==0x0d){//cmd finish
			if(dbcmd_len!=0){//if then end of command isn't space the 0x0d is the paramter's seperate.
				dbcmd[argc][dbcmd_len]='\0';
				if(argc<MAX_DB_ARGC){
					argc++;
				}
				else{
					printk("\n Too many paramter in this command.retry again.:).");
					printk(PROMPT);
					error_flag=1;
				}			
			}
			if(!error_flag){//no  error occured.
				if((argc==0)&&(dbcmd_len==0)){//empty command.
				}
				else if(!strcmp(dbcmd[0],"paprom")){//对APROM编程
				}
				else if(!strcmp(dbcmd[0],"pldrom")){//对LDROM编程
				}
				else if(!strcmp(dbcmd[0],"black")){
					printk("\n Black all screen.");
					black_all();
				}
				else if(!strcmp(dbcmd[0],"clrs")){
					printk("\n Clera all screan.",NULL);
					clear_all();
				}
				else if(!strcmp(dbcmd[0],"date")){
					if(!strcmp(dbcmd[1],"show")){						
						printk("\n  Show time.",NULL);	
						show_date_on=1;
						updtime=0xff;
						rtc_read_timeout=1;
					}
					else if(!strcmp(dbcmd[1],"hide")){//off
						printk("\n Hide time.",NULL);
						show_date_on=0;
#ifdef HB320
						clr_area(POS_TIMEX,POS_TIMEY,8,48);
#else
						clr_area(POS_TIMEX,POS_TIMEY,16,99);
#endif
					}
					else if(!strcmp(dbcmd[1],"init")){//off
						printk("\n Init rtc");
					}
				}
				else if(!strcmp(dbcmd[0],"draw")){
					if(!strcmp(dbcmd[1],"pic")){
						printk("\n Draw picture.");					
					}
					else if(!strcmp(dbcmd[1],"line")){
						printk("\n Draw line");
						hm_pointer.angel=rtc.hour*30;
						hm_pointer.angel +=rtc.minute>>1;//hour pointer.
						hm_pointer.len=20;
						draw_line(&hm_pointer);
						hm_pointer.angel=rtc.minute*6;//hour pointer.
						hm_pointer.len=25;
						draw_line(&hm_pointer);
					}
				}
				else if(!strcmp(dbcmd[0],"address")){//show storey xx
					if(argc==2){
						intnum=atoi(dbcmd[1]);
						if(intnum>31){
							printk("\n Address must less than 31");
						}
						else{
							myaddress=(unsigned char )intnum;
							intnum=EEPROM_MACHINE_ADD;
							AT24C64_wbytes((unsigned char *)&intnum,1,&myaddress);
						}
					}
					printk("\n My address=%bx.",myaddress);
				}
				else if(!strcmp(dbcmd[0],"storey")){//show storey xx
					if(argc==2){
						intnum=atoi(dbcmd[1]);
						draw_storey(POS_STOREY_ORGX,POS_STOREY_ORGY,(unsigned char )intnum);
						printk("\n Show strory %c",(unsigned char )intnum);
					}
				}
				else if(!strcmp(dbcmd[0],"fwrite")){
					if(argc==2){
						ch=xatouc(dbcmd[1]);
						dwn_add_debug.l=0x2000;
						for(i=0;i<8;i++){
							printk(" w=%c ",ch);	
							write_flash(&dwn_add_debug,ch);
							dwn_add_debug.l++;
						}
						printk("\n Write flash 8 byte");
			   		}
				}
				else if(!strcmp(dbcmd[0],"fread")){
					read_flash(0x8,0,8,flash_rbuf);
					printk("\n Flash data=",NULL);
					for(i=0;i<8;i++){	
						printk("%bx ",*(flash_rbuf+i));
					}
				}
				else if(!strcmp(dbcmd[0],"fesr")){
					if(argc==2){
						intnum=atoi(dbcmd[1]);
						ch=(unsigned char )intnum;
						if(ch<71){
							printk("\n Erase total %c sectors.",ch);
							for(i=0;i<ch;i++){//擦除数字和字母分区。
								erase_flash(1,i);
							}
						}
					}
				}
				else if(!strcmp(dbcmd[0],"fesa")){
					if(argc==2){
						intnum=atoi(dbcmd[1]);
						ch=(unsigned char )intnum;
						erase_flash(1,ch);
						printk("\n Erase sectors=%c.",ch);
					}
				}
				else if(!strcmp(dbcmd[0],"num")){
					if(argc==2){
						intnum=atoi(dbcmd[1]);
						ch=(unsigned char )intnum;
						draw_wordw24(0,0,48,number24x48[ch]);//centigrade
						printk("\n ch=%c",ch);
				 	}
				}
				else if(!strcmp(dbcmd[0],"fecp")){
					printk("\n Erase chip.");
					erase_flash(0,8);
				}
				else if(!strcmp(dbcmd[0],"fwtest")){
					printk("\n Write flash test data.");
					dwn_add_debug.l=0x2000;
					for(i=0;i<8;i++){
						printk(" %bx",*(flash_wbuf+i));	
						write_flash(&dwn_add_debug,*(flash_wbuf+i));
						dwn_add_debug.l++;
					}
				}
				else if(!strcmp(dbcmd[0],"ry")){
					SD2000_read_time(&rtc);
					printk(" year=%bx",rtc.year);
					printk(" month=%bx",rtc.month);
					printk(" dayom=%bx",rtc.dayom);
					printk(" week=%bx",rtc.week);
					printk(" hour=%bx",rtc.hour);
					printk(" minute=%bx",rtc.minute);//becuase it is bcd code.
				}
				else if(!strcmp(dbcmd[0],"rh")){
					SD2000_read_hour(&rtc);
				}
				else if(!strcmp(dbcmd[0],"h24")){//24 hour
					SD2000_set_status(0x02);//24hour 1HZ interrupt.
				}
				else if(!strcmp(dbcmd[0],"rtcsta")){//
					ch=xatouc(dbcmd[1]);
					SD2000_set_status(ch);
					printk(" rtcsta=%bx.",ch);
				}
				else if(!strcmp(dbcmd[0],"h12")){//12 hour
				}
				else if(!strcmp(dbcmd[0],"year")){
					if(argc==2){	
						intnum=atoi(dbcmd[1]);
						intnum %=100;
						ch=(unsigned char )intnum;
						if(ch<99){
							rtc.year=chtobcd(ch);
							SD2000_set_time(&rtc);
							printk("\n Set year=%c ok.",ch);
						}
					}
				}
				else if(!strcmp(dbcmd[0],"month")){
					if(argc==2){	
						intnum=atoi(dbcmd[1]);
						ch=(unsigned char )intnum;
						if(ch<13){
							rtc.month=chtobcd(ch);
							SD2000_set_time(&rtc);
							printk("\n Set month=%c ok.",ch);
						}
					}
				}
				else if(!strcmp(dbcmd[0],"day")){
					if(argc==2){	
						intnum=atoi(dbcmd[1]);
						ch=(unsigned char )intnum;
						if(ch<32){
							rtc.dayom=chtobcd(ch);
							SD2000_set_time(&rtc);
							printk("\n Set day=%c ok.",ch);
						}
					}
				}
				else if(!strcmp(dbcmd[0],"hour")){
					if(argc==2){	
						intnum=atoi(dbcmd[1]);
						ch=(unsigned char )intnum;
						if(ch<24){
							rtc.hour=chtobcd(ch);
							SD2000_set_time(&rtc);
							printk("\n Set hour=%c rtc.hour=%bx ok.",ch,rtc.hour);
						}
					}
				}
				else if(!strcmp(dbcmd[0],"minute")){
					if(argc==2){	
						intnum=atoi(dbcmd[1]);
						ch=(unsigned char )intnum;
						if(ch<60){
							rtc.minute=chtobcd(ch);
							SD2000_set_time(&rtc);
							printk("\n Set minute=%c ok.",ch);
						}
					}
				}
				else if(!strcmp(dbcmd[0],"second")){
					if(argc==2){	
						intnum=atoi(dbcmd[1]);
						ch=(unsigned char )intnum;
						if(ch<60){
							rtc.second=chtobcd(ch);
							SD2000_set_time(&rtc);
							printk("\n Set second=%c ok.",ch);
						}
					}
				}
				else if(!strcmp(dbcmd[0],"time")){
					if(argc==4){	
						intnum=atoi(dbcmd[1]);
						ch=(unsigned char )intnum;
						rtc.hour=chtobcd(ch);
						intnum=atoi(dbcmd[2]);
						ch=(unsigned char )intnum;
						rtc.minute=chtobcd(ch);
						intnum=atoi(dbcmd[3]);
						ch=(unsigned char )intnum;
						rtc.second=chtobcd(ch);
						SD2000_set_time(&rtc);
						send_hbs_msg(MSG_HBS_UPD_TIME);
						printk("\n Set hour minute second ok.",ch);
					}
				}
				else if(!strcmp(dbcmd[0],"m")){
					if(argc==2){	
						intnum=atoi(dbcmd[1]);
						ch=(unsigned char )intnum;
						if(ch<60){
							rtc.minute=chtobcd(ch);
							SD2000_set_time(&rtc);
							printk("\n Set minute=%c ok.",ch);
						}
					}
				}
				else if(!strcmp(dbcmd[0],"setf")){
                	extern void SD2000_set_freq(unsigned char ch1,unsigned char ch2, unsigned char ch3);
					flash_rbuf[0]=xatouc(dbcmd[1]);
					flash_rbuf[1]=xatouc(dbcmd[2]);
					flash_rbuf[2]=xatouc(dbcmd[3]);
					SD2000_set_freq(flash_rbuf[0],flash_rbuf[1], flash_rbuf[2]);
				}
				else if(!strcmp(dbcmd[0],"wd")){
					if(argc==2){
						if(!strcmp(dbcmd[1],"s")){
							tmstart();
							printk("\n start convert...");
						}
						else if(!strcmp(dbcmd[1],"r")){
							others.temperature=tmrtemp_all();
							printk("\n temperature=%c.",others.temperature);
						}
						else if(!strcmp(dbcmd[1],"p")){
							others.print |=PRNT_TM;
							printk("\n Print temperature convert result.");
						}
						else if(!strcmp(dbcmd[1],"np")){
							others.print &=~PRNT_TM;
							printk("\n Don't print temperature convert result.");
						}
						else if(!strcmp(dbcmd[1],"show")){
							show_wd_on=1;
							printk("\n Show temperate.");
						}
						else if(!strcmp(dbcmd[1],"hide")){
							show_wd_on=0;
#ifdef HB320
						clr_area(POS_SHOW_WDX,POS_SHOW_WDY,8,16);
#else
						clr_area(POS_SHOW_WDX,POS_SHOW_WDY,20,33);
#endif
							printk("\n Hide temperate.");
						}
					}
					else{
						printk("\n temperature=%c.",others.temperature);
					}								
				}
				else if(!strcmp(dbcmd[0],"weeprom")){
					eeprom_dbgadd=32;
					AT24C64_wbytes((unsigned char *)&eeprom_dbgadd,8,flash_wbuf);
					printk("\n Write eeprom=");
					for(i=0;i<8;i++){
						printk(" %bx",flash_wbuf[i]);
					}
				}
				else if(!strcmp(dbcmd[0],"reeprom")){
					eeprom_dbgadd=32;
					AT24C64_rbytes((unsigned char *)&eeprom_dbgadd,8,flash_rbuf);
					printk("\n read eeprom=");
					for(i=0;i<8;i++){
						printk(" %bx",flash_rbuf[i]);
					}
				}
				else if(!strcmp(dbcmd[0],"initeeprom")){
					printk("\n Init eeprom");
					init_eeprom();
				}
				else if(!strcmp(dbcmd[0],"weight")){
					if(argc==2){
						intnum=atoi(dbcmd[1]);
						if(intnum>10000){
							printk("\n Too weight,error");
						}
						else{
							printk("\n Weight=%d",intnum);
							i=(unsigned char)(intnum/1000);
							show_notice.weight[0]=i%10;
							intnum %=1000;
							i=(unsigned char)(intnum/100);
							show_notice.weight[1]=i%10;
							intnum %=100;
							i=(unsigned char)(intnum/10);
							show_notice.weight[2]=i%10;
							intnum %=10;
							show_notice.weight[3]=(unsigned char)(intnum);
							intnum=EEPROM_LOAD_ADD;
							AT24C64_wbytes((unsigned char *)&intnum,EEPROM_LOAD_LEN,show_notice.weight);//write load.
						}
					}
					else{
						printk("\n Command error");
					}
				}
				else if(!strcmp(dbcmd[0],"person")){
					if(argc==2){
						intnum=atoi(dbcmd[1]);
						ch=(unsigned char )intnum;
						if(ch>100){
							printk("\n Person too many");
						}
						else{
							printk("\n Person=%c",ch);
							show_notice.person[0]=ch/10;
							show_notice.person[1]=ch%10;
							intnum=EEPROM_PERSON_ADD;
							AT24C64_wbytes((unsigned char *)&intnum,EEPROM_PERSON_LEN,show_notice.person);//write person
						}
					}
					else{
						printk("\n Command error");
					}
				}
				else if(!strcmp(dbcmd[0],"otis")){
					show_notice.otis=1;
					intnum=EEPROM_OTIS_ADD;
					AT24C64_wbytes((unsigned char *)&intnum,EEPROM_OTIS_LEN,&show_notice.otis);//write otis.
					printk("\n Show OTIS");
				}
				else if(!strcmp(dbcmd[0],"xzotis")){
					show_notice.otis=0;
					intnum=EEPROM_OTIS_ADD;
					AT24C64_wbytes((unsigned char *)&intnum,EEPROM_OTIS_LEN,&show_notice.otis);//write xzotis.
					printk("\n Show XZOTIS");
				}
				else if(!strcmp(dbcmd[0],"timer")){
					for(i=0;i<TIMER_NUM;i++){
						printk(" TT[%c].en=%bx.",TT[i].enable);
					}
				}
				else if(!strcmp(dbcmd[0],"refresh")){
					printk("\n refresh=%bx.",refresh);
				}
				else if(!strcmp(dbcmd[0],"refresh")){
					printk("\n Timer tempera cnt=%d en=%bx",TT[TMPERA_TIMER].count,TT[TMPERA_TIMER].enable);
				}				
				else if(!strcmp(dbcmd[0],"reserve")){
					if(!strcmp(dbcmd[1],"time")){	
					}
				}
				else if(!strcmp(dbcmd[0],"fadd")){//
					ch=xatouc(dbcmd[1]);
					FLASHADD=ch;
					printk("\n Fadd=%bx.",ch);
				}
				else if(!strcmp(dbcmd[0],"dr24")){//
					if(argc==2){
						intnum=atoi(dbcmd[1]);
						ch=(unsigned char )intnum;
						draw_asc16x24(37,10,ch);
					}
				}
				else if(!strcmp(dbcmd[0],"dr8")){//
					if(argc==2){
						intnum=atoi(dbcmd[1]);
						ch=(unsigned char )intnum;
						draw_wordw8(37,10,16,num8x16+ch*16);
					}
				}
				else if(!strcmp(dbcmd[0],"ttimer")){
					test_timer_len=atoi(dbcmd[1]);
					printk("\n Test timer len=%d",test_timer_len);
				}
				else{
					printk("\n Bad command.");
				}
		  	}
			else{//reset error flag and search command again.
				error_flag=0;
			}
			printk(PROMPT);
			dbcmd_len=0;
			space_flag=1;
			argc=0;
		}
		else{
			if(dbcmd_len<DBCMD_LEN-1){
				if(dsr_buf[dsr_tail]==' '){
					if(space_flag==0){//this is the end of argmet paramter.
						dbcmd[argc][dbcmd_len]='\0';//dsr_buf[dsr_tail];						
						if(argc<MAX_DB_ARGC){
							argc++;
					   	}
						else{
							printk("\n Too many paramter in this command.retry again. :).");
							printk(PROMPT);
							error_flag=1;
						}						
					}
					space_flag=1;
					dbcmd_len=0;//ready to receive next paramter.
					//dsr_tail++;
					//dsr_tail %=DSR_LEN;					
			  	}
				else{
					space_flag=0;
					dbcmd[argc][dbcmd_len]=dsr_buf[dsr_tail];
					dbcmd_len++;
					dbcmd_len %=DBCMD_LEN;
					//dsr_tail++;
					//dsr_tail %=DSR_LEN;
			 	}
		  	}
			else{
				printk("\n Input too long.Don't make joke with me :).");
				dbcmd_len=0;
				printk(PROMPT);	
				error_flag=1;
			}
			print_char(dsr_buf[dsr_tail]);//echo
		}
		dsr_tail++;
		dsr_tail %=DSR_LEN;
		return 1;
	}
	else{//debug receive buf is empty.
		return 0;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -