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

📄 mdt.c

📁 这是一个用C写的单片机程序
💻 C
📖 第 1 页 / 共 4 页
字号:
				 Disp_Message();
	 		}
		}
		else{
			if(Active_Line<(Total_Line-2)) ++Active_Line;
			if((Total_Line-Start_Line)>7){
				if(Active_Line>Start_Line+7){
				 ++Start_Line;
				}
			}
			Reverse_Line(Active_Line);
			Disp_Title();
			Disp_Message();
		}
	}
	
	else{
		if(Key_Type) {
			if(Start_Line>0) {
				--Start_Line;
				Disp_Title();
				Disp_Message();
			}
		}
		else{
			if(Active_Line>0) --Active_Line;
			if(Active_Line<Start_Line) --Start_Line;
			Reverse_Line(Active_Line);
			Disp_Title();
			Disp_Message();
		}
	}
}

if(StandBy_Flag==1){
	Wait_Time=0; First=1; Stand_N=0;
	StandBy_Flag=0;
	Disp_Title();
	Disp_Message();
}

return;
}

//============================================================
//液晶显示状态栏内容
//============================================================
void Disp_Status()
{
unsigned int i=0,j=0;

		while(i<16){
			Write_S6b0741_Reg(SET_PAGE+i);
			Write_S6b0741_Reg(SET_COLUMN_MSB);
			Write_S6b0741_Reg(SET_COLUMN_LSB);
			for(j=0;j<12;++j){
				Write_S6b0741_Data(Buff_Page[i].Column[j]);
			}
			++i;
		}
return;
}

//============================================================
//存储状态显示内容
//============================================================
void Store_Status()
{
unsigned char ch,i;

//	Clr_Status_Buff();

	Line_Tab=0;
	while(Read_Rx()!='^');
    while(Read_Rx()!='I');
	ch=Read_Rx();
    switch(ch){
        case 'C':
		   ch=Read_Rx();

		   Set_XY(0,0);
		   Load_Symbol(ant);
		   V_Write_HZ();

		   switch(ch){
		       case '0':{Set_XY(0,0);Print_String(blank,5);}break;
			   case '1':{Set_XY(2,0);Load_Symbol(ant0);V_Write_HZ();}break;
			   case '2':{Set_XY(2,0);Load_Symbol(ant1);V_Write_HZ();}break;
			   case '3':{Set_XY(2,0);Load_Symbol(ant2);V_Write_HZ();}break;
			   case '4':{Set_XY(2,0);Load_Symbol(ant3);V_Write_HZ();}break;
			   case '5':{Set_XY(2,0);Load_Symbol(ant4);V_Write_HZ();}break;
			   default: {Set_XY(2,0);Load_Symbol(ant4);V_Write_HZ();}break;
		   }
		   break;
		case 'R':
		    ch=Read_Rx();
			Set_XY(6,0); Print_String(blank,5);
			switch(ch){
		        case '0':break;
			    case '1':
					if(IP_En){
						Set_XY(6,0); Load_Symbol(cdma);V_Write_HZ();
						Set_XY(8,0); Load_Symbol(tcp);V_Write_HZ();
					}
					else{
						Set_XY(6,0); Load_Symbol(cdma);V_Write_HZ();
                    }
					break;
			    default:
				 break;
			}break;
		case 'D':
		    ch=Read_Rx();
			switch(ch){
				case '0': IP_En=0; break;
				case '1': IP_En=1; break;
				default: IP_En=0; break;
			}break;
		case 'G':
	        ch=Read_Rx();
			Set_XY(12,0);
			ch=Read_Rx();
			switch(ch){
	    	    case '0':{for(i=0;i<4;i++)Print_String(blank,2);}break;
		    	default: {
					for(i=0;i<4;i++)Print_String(blank,2);
					Set_XY(12,0);
					ch=ch-'0';
					if(ch>4) ch=4;
					for(i=0;i<ch;i++){
				    	Load_Symbol(star);
						V_Write_HZ();
						}
				}break;
			}break;
    }
    while(Read_Rx()!='}');
//	LCM_INIT();
return;
}

//============================================================
//解释接收数据
//============================================================
void Explain()
{
unsigned char ch;

while(Read_Rx()!='{');
ch=Read_Rx();
if(ch=='S'){ Store_Message(); Store_Vram(); Disp_Title(); Disp_Message();}
else if(ch=='C') {Store_Status(); Disp_Status();}
else while(Read_Rx()!='}');
return;
}


//==================================================================
//				串口初始化
//==================================================================
void Init_Rs232()
{
	SCON = 0x50; //SCON: serail mode 1, 8-bit UART, enable ucvr
	TMOD |= 0x20; //TMOD: timer 1, mode 2, 8-bit reload
	PCON |= 0x80; //SMOD=1;
	TH1 = 0x100-BT; //Baud:115200/BT BT>=1(INTGREDE) fosc=22.1184MHz
	IE |= 0x90; //Enable Serial Interrupt
	TR1 = 1; // timer 1 run
	TI=0;
   Tx_Done=0;
}



//============================================================================
//			串口接收中断子程
//============================================================================
void Serial () interrupt 4  using 1
{  
unsigned char ch;

    if(RI){
		ch=SBUF;
		RI=0;
        if(En_Lcd_Flag) Off_Lcd();
		if(ch=='{')	RS232_Flag=1;
 		if(RS232_Flag) {
			Recieve_Buff[P_Rx]=ch;
			++P_Rx;
		}
		if(ch=='}') RS232_Flag=0;
        if(En_Lcd_Flag) En_Lcd();
	}
    else{
        if(TI&Tx_Done){
            TI=0;
            SBUF=Transfer[T_Tx];
            if(++T_Tx==Tx_Length) Tx_Done=0;
        }
        else
            TI=0;
	}
}


//============================================================
//CPU看门狗计数器+待机时间计数器
//============================================================
void Init_Time0()
{
   TH0=-221184/12/256;  
   TL0=-221184/12%256;
   IE|=0x02;
   TF0=0;
   TR0=1;
   	WDTRST=0x1E;
	WDTRST=0xE1;

}

//============================================================
//CPU看门狗+待机时间中断
//============================================================
void IntTime0 () interrupt 1
{
   TH0=-221184/12/256;  
   TL0=-221184/12%256;
	WDTRST=0x1E;
	WDTRST=0xE1;
    if(Wait_Time<Stand_Time) ++Wait_Time;
	else{ 
		if(Stand_Count<300) ++Stand_Count;
		}
}


//==================================================================
//				键盘扫描程序
//==================================================================
void Key_Scan()
{
unsigned int key_count=0;

     Key_Scroll_Up=1;
     Key_Scroll_Down=1;
     Key_Menu=1;
	 Key_Enter=1;
     Key_Cancel=1;
     Key_Forward=1;
     Key_Back=1;
     Key_Call=1;

	if(!Key_Enter){
		while(!Key_Enter);
	    while(Tx_Done);
	    if(Key_Type){
	        Copy_Key(s6_enter,Transfer);
	        Int_Tx(12);   
	    }
	    else{ 
		    Copy_Key(s1_enter,Transfer);
	        Transfer[12]=Active_Line+0x30; 
		    Int_Tx(14);
	    }
	return;
	}

	if(!Key_Menu){
		while(!Key_Menu);
	    while(Tx_Done);    
	    if(Key_Type) Copy_Key(s6_menu,Transfer);
	    else Copy_Key(s1_menu,Transfer);
		Int_Tx(11);
	return;
	}

	if(!Key_Cancel){
		while(!Key_Cancel);
	    while(Tx_Done);    
	    if(Key_Type) Copy_Key(s6_cancel,Transfer);
	    else Copy_Key(s1_cancel,Transfer);
		Int_Tx(11);
	return;
	}

	if(!Key_Forward){
		while(!Key_Forward);
	    while(Tx_Done);
	    if(Key_Type){
	        Copy_Key(s6_forward,Transfer);
	 		Int_Tx(11);
	    }
	    else{
	        Copy_Key(s1_forward,Transfer);
	        Transfer[11]=Active_Line+0x30; 
		    Int_Tx(13);
	    }
	return;
	}

	if(!Key_Back){
		while(!Key_Back);
	    while(Tx_Done); 
	    if(Key_Type){
	        Copy_Key(s6_back,Transfer);
	        Int_Tx(11);
	    }
	    else{
	        Copy_Key(s1_back,Transfer);
	        Transfer[12]=Active_Line+0x30; 
		    Int_Tx(14);
	    }
	return;
	}

	if(!Key_Call){
		while(!Key_Call);
        while(Tx_Done);
        if(Key_Type){
            Copy_Key(s6_call,Transfer);
            Int_Tx(11);
        }
        else{
            Copy_Key(s1_call,Transfer);
            Transfer[11]=Active_Line+0x30; 
 		    Int_Tx(13);
        }
	return;
    }

  	if((Key_Scroll_Down==0)&&(Key_Scroll_Up==0)){
	 	while(Key_Scroll_Down==Key_Scroll_Up){
			Delay(1); ++key_count;
			if(key_count>1000) return;
		}
		if(Key_Scroll_Up) Roll_Arrow=1;
		else Roll_Arrow=0;
		Roll_Screen();
		return;
	}
   	return;
}

//============================================================
//在液晶上显示图片内容
//============================================================
//n_com 液晶显示起始行(线) n_page 图像占据字节宽度 n_height 图像占据像素高度
void Print_Window(unsigned char n_com,unsigned char n_page, unsigned char n_height,unsigned char *pic)
{
unsigned char i=0,n=0;
unsigned char col_msb,col_lsb;
unsigned char com_n;

	while(n<n_height){
		com_n=n_com+n;
		col_lsb=com_n&0x0f;
		col_msb=com_n>>4;
		while(i<n_page){
			Write_S6b0741_Reg(SET_PAGE+i+(15-n_page)/2);
			Write_S6b0741_Reg(SET_COLUMN_MSB+col_msb);
			Write_S6b0741_Reg(SET_COLUMN_LSB+col_lsb);
			Write_S6b0741_Data(pic[n_page*n+i]);
			++i;
		}
		++n;i=0;
	}

}

//============================================================
//刷新待机图片局部内容
//============================================================
void Print_Box(unsigned char *pic)
{
unsigned char i=0,n=0;
unsigned char col_msb,col_lsb;
unsigned char com_n;

	while(n<42){
		com_n=42+14+n;
		col_lsb=com_n&0x0f;
		col_msb=com_n>>4;
		while(i<6){
			Write_S6b0741_Reg(SET_PAGE+i+8);
			Write_S6b0741_Reg(SET_COLUMN_MSB+col_msb);
			Write_S6b0741_Reg(SET_COLUMN_LSB+col_lsb);
			Write_S6b0741_Data(pic[6*n+i]);
			++i;
		}
		++n;i=0;
	}

}
//==========================================================
//						主程序
//==========================================================
void main()
{
    Init_Rs232();
    Init_Time0();
    IP=0x10;


	S6b0741_Init();
	Write_S6b0741_Reg(DISP_ON);	
	Clear_Screen(0x00);
   
	P1=0xff;
    RS232_Flag=0;
	Clr_Mess_Buff();
	Clr_Status_Buff();
	Total_Line=10;
	Clr_Message_Buff();
    Set_XY(0,9);
    Print_SN();
    Disp_Message();    
	Print_Window(42,15,64,wonstar1);
	Total_Line=Mess_Line;
	Clr_Message_Buff();
	Total_Line=0;
	Active_Line=0;
    Roll_En=0;
	while(1){
    	Explain();
    }

}



⌨️ 快捷键说明

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