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

📄 uart.c

📁 进行单片机与LCD的接口通讯与显示。使用清华的液晶。
💻 C
字号:
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
int idata buf[30]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
uchar idata buf_point=0;
uchar pf;
uchar over=0;
uchar rec=0;
int ch;
uchar  rec_over=0;
int Keybefore;
extern void dispes(uchar position1,uchar position2,uchar chanum,uchar* p);
extern CLEAR();
extern uchar code menu_str[97][30];
extern void msec(uint x);
extern uchar dispint(uchar,uchar,int);
extern uchar dispint_f(uchar position1,uchar position2,int value);
extern void dispf(uchar position1,uchar position2,float value,uchar preci);
extern void dispf_f(uchar position1,uchar position2,float value,uchar preci);
extern KeyState;
extern KeyFuncIndex;
extern head;

void Uart_init(void)
{
 	TMOD=0x20;
	PCON=0x00;
	SCON=0x50;
	TH1=0x0f4;
        TL1=0x0f4;
	TR1=1;
	ES=1;
        EA=1;
}

/*void send(uchar idata *d,uchar length)
{ uchar i;
       SBUF=0x61;
       while(over==0);over=0;
       pf=0;
       pf=pf^0x61;
       SBUF=length;
       while(over==0);over=0;
       pf=pf^length;
       for(i=0;i<length;i++){
          SBUF=d[i];
           while(over==0);over=0;
          pf^=d[i];
       }
       SBUF=pf;
        while(over==0);over=0;
       SBUF=0x6e;
        while(over==0);over=0;
     }    */

void send(uchar idata d)
  {     uint i;
        SBUF=d;
       while(over==0);over=0;
       for(i=0;i<100;i++){;}
   }
void receive(void)interrupt 4 using 3
  {
    if(TI)
    {
       TI=0;
       over=1;
    }
   else if(RI)
    {
        RI = 0;
        ch=SBUF;
        if(ch==head||rec)
        { rec=1;
         buf[buf_point++]=ch;
        if(buf_point>=buf[1]+2)
          {buf_point=0;
          rec_over=1; };
         };
       /*此处验证头和校验*/
       if(rec_over==1)
       {  rec=0;
         rec_over=0;
       switch(buf[2])
       {
         case  1: KeyState=1;   //receive normal display
                     KeyFuncIndex=3;
                     break;
         case  2:  KeyState=1;  //receive fault. ack.
                     KeyFuncIndex=8;
                     break;
         case  3:  KeyState=1;  //receive fault. acked.
                     KeyFuncIndex=10;
                     break;
         case  10:  KeyState=1;   //receive history events
                     KeyFuncIndex=14;
                     break;
         case  11:  KeyState=1;       //receive data/time setting
                     KeyFuncIndex=17;
                     break;
         case  12:   KeyState=1;       //receive time modified
                     KeyFuncIndex=28;
                     break;
         case  13:  KeyState=1;       //receive  language
                     KeyFuncIndex=31;
                     break;
         case  14:  KeyState=1;       //receive language modified
                     KeyFuncIndex=34;
                      break;
         case  15:  KeyState=1;       //receive scale
                     KeyFuncIndex=37;
                     break;
         case  16:  KeyState=1;       //receive scale modified
                     KeyFuncIndex=40;
                     break;
         case  17:  KeyState=1;       //receive motor specification
                     KeyFuncIndex=62;
                     break;
         case  18:  KeyState=1;       //receive motor specification modified
                     KeyFuncIndex=73;
                     break;
         case  19:  KeyState=1;       //receive frequency setting
                     KeyFuncIndex=74;
                     break;
         case  20:  KeyState=1;       //receive frequency setting modified
                     KeyFuncIndex=85;
                     break;
         case  21:  KeyState=1;       //receive group in operation
                     KeyFuncIndex=86;
                     break;
         case  22:  KeyState=1;       //receive group in operation modified
                     KeyFuncIndex=99;
                     break;
         case  23:   KeyState=1;       //receive control mode
                    KeyFuncIndex=100;
                    break;
         case  24:   KeyState=1;       //receive control mode modified
                    KeyFuncIndex=106;
                    break;
         case  25:  KeyState=1;       //receive fwd/rev
                     KeyFuncIndex=107;
                     break;
         case  26:  KeyState=1;       //receive fwd/rev modified
                     KeyFuncIndex=114;
                     break;
         case  27:  KeyState=1;       //receive DC apply
                     KeyFuncIndex=115;
                     break;
         case  28:  KeyState=1;       //receive DC apply  modified
                     KeyFuncIndex=124;
                     break;
         case  29:  KeyState=1;       //receive limit parameters
                     KeyFuncIndex=125;
                     break;
          case  30:  KeyState=1;       //receive limit parameters modified
                     KeyFuncIndex=138;
                     break;
         case  31:  KeyState=1;       //receive calbration
                     KeyFuncIndex=139;
                     break;
          case  32:  KeyState=1;       //receive calbration modified
                     KeyFuncIndex=156;
                     break;
         case  40:  KeyState=1;       //receive general mesument
                     KeyFuncIndex=163;
                     break;
         case  41:  KeyState=1;       //receive genaral states
                     KeyFuncIndex=165;
                     break;
         case  45:  KeyState=1;       //receive basic v/f control
                    KeyFuncIndex=167;
                    break;
         case  46:  KeyState=1;       //receive basic v/f control modified
                    KeyFuncIndex=178;
                    break;
         case  65:  KeyState=1;       //receive v/f relation
                     KeyFuncIndex=181;
                     break;
         case  66:  KeyState=1;       //receive v/f relation modified
                     KeyFuncIndex=186;
                     break;
         case  60:  KeyState=1;       //receive phase A
                     KeyFuncIndex=179;
                     break;
         case  62:  KeyState=1;       //receive phase B
                     KeyFuncIndex=179;
                     break;
         case  64:  KeyState=1;       //receive phase C
                     KeyFuncIndex=179;
                     break;
         case  100: KeyState=1;      //receive communication signal
                     KeyFuncIndex=191;
                     break;
         case  101: KeyState=1;      //receive self-checking signal
                     KeyFuncIndex=192;
                     break;
         case  102: KeyState=1;      //receive communication signal
                     KeyFuncIndex=193;
                     break;
         case  103: KeyState=1;      //receive main switch closed
                     KeyFuncIndex=194;
                     break;
         case  104:  KeyState=1;      //receive charging finished
                     KeyFuncIndex=195;
                     break;
         case  105:  KeyState=1;      //receive impulse released
                     KeyFuncIndex=196;
                     break;
         case  106:  KeyState=1;      //speeding up finished
                     KeyFuncIndex=197;
                     break;
         case  99:   if(KeyFuncIndex!=198)
                    { Keybefore=KeyFuncIndex;}    //V I F MODE V/F
                     KeyState=1;
                     KeyFuncIndex=198;
                     break;
         case  110:   KeyState=1;     //normal down
                     KeyFuncIndex=199;
                     break;
         case  111:   KeyState=1;     //fault down
                     KeyFuncIndex=200;
                     break;
         default : KeyFuncIndex=88;
                     break;
      }

      }
     }
  }

⌨️ 快捷键说明

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