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

📄 cm160128.c

📁 keil c51编写的LCD 12864像素LCD显示屏程序,,通过调用函数,显示grom字库中的7千多个简体中文和字符
💻 C
📖 第 1 页 / 共 2 页
字号:
                    STR6[3] = unintData%10;
                    unintData /= 10;
                    STR6[2] = unintData%10;
                    break;
             case 2://放大倍数为4
             case 0x0a:
                    unintData /= 4;
                    STR6[0] = 0x0a;
                    STR6[1] = 0x0a;
                    if(unintData > 0)
                    {
                         STR6[2] = 0x0a;
                    }
                    else if(unintData < 0)
                    {
                         STR6[2] = 0x0c;
                    }
                    else
                    {
                         STR6[2] = 0x0a;
                    }

                    unintData = abs(unintData);
                    STR6[5] = unintData%10;
                    unintData /= 10;
                    STR6[4] = unintData%10;
                    unintData /= 10;
                    STR6[3] = unintData%10;
                    break;
              case 3://一位小数点//放大倍数为16
              case 0x0b:
                    unintData *= 10;
                    unintData /= 16;

                    if(unintData > 0)
                    {
                         STR6[0] = 0x0a;
                    }
                    else if(unintData < 0)
                    {
                         STR6[0] = 0x0c;
                    }
                    else
                    {
                         STR6[0] = 0x0a;
                    }
                    unintData = abs(unintData);
                    STR6[5] = unintData%10;
                    unintData /= 10;
                    STR6[4] = 0x0b;
                    STR6[3] = unintData%10;
                    unintData /= 10;
                    STR6[2] = unintData%10;
                    unintData /= 10;
                    STR6[1] = unintData%10;
                break;
              case 4://两位小数点//放大倍数为64
              case 0x0c:
                    //unintData /= 16;
                    unintData *= 1.5625;

                    if(unintData > 0)
                    {
                         STR6[0] = 0x0a;
                    }
                    else if(unintData < 0)
                    {
                         STR6[0] = 0x0c;
                    }
                    else
                    {
                         STR6[0] = 0x0a;
                    }
                    unintData = abs(unintData);
                    STR6[5] = unintData%10;
                    unintData /= 10;
                    STR6[4] = unintData%10;
                    unintData /= 10;
                    STR6[3] = 0x0b;
                    STR6[2] = unintData%10;
                    unintData /= 10;
                    STR6[1] = unintData%10;
                    break;
              default:
                    break;
        }
        DISHAZIT2(0,0x10,STR6[0]);
        DISHAZIT2(3,0x10,STR6[1]);
        DISHAZIT2(6,0x10,STR6[2]);
        DISHAZIT2(9,0x10,STR6[3]);
        DISHAZIT2(12,0x10,STR6[4]);
        DISHAZIT2(15,0x10,STR6[5]);
}
//显示采样时间值
void DispSampleTime(unsigned char ucData)
{
        unsigned char data ucTime = 0;
        ucData = ucData & 0x0f;

        if(ucData == 0x01)
        {
            ucTime = 1;
        }
        else if(ucData == 0x02)
        {
            ucTime = 2;
        }
        else if(ucData == 0x03)
        {
            ucTime = 25;
        }
        else if(ucData == 0x04)
        {
            ucTime = 50;
        }
        else if(ucData == 0x05)
        {
            ucTime = 100;
        }
        else if(ucData == 0x06)
        {
            ucTime = 200;
        }

        DISDASC(0x0e,0x09,0x80+(ucTime%10)*2);
        ucTime /= 10;
        DISDASC(0x0c,0x09,0xa2);
        DISDASC(0x0d,0x09,0x80+(ucTime%10)*2);
        ucTime /= 10;
        DISDASC(0x0b,0x09,0x80+(ucTime%10)*2);
        DISDASC(0x0f,0x09,0xa0);
}
//显示示放大倍数值
void DispAmpMultiple(unsigned char ucAmpMW)
{
                if(ucAmpMW > 0x07)
                {
                    DISHAZIT(17,8*9,0x06);
                }
                else
                {
                    DISHAZIT(17,8*9,0x05);
                }

       		switch(ucAmpMW)
		{
			case 0x02:
                        case 0x0a:
				ucAmpMW = 4;
				break;
			case 0x03:
                        case 0x0b:
				ucAmpMW = 16;
				break;
			case 0x04:
                        case 0x0c:
				ucAmpMW = 64;
				break;
			default:
				ucAmpMW = 1;
				break;
		}

        DISDASC(0x0b,0x0b,0x96);
        DISDASC(0x0d,0x0b,0x80+(ucAmpMW/10)*2);
        DISDASC(0x0e,0x0b,0x80+(ucAmpMW%10)*2);
}
//显示负高压值
void DispVoltege(unsigned char ucData)
{
        unVolt = HVOLT[ucData];

        if(unVolt < 200)//高压小于200时显示为"0"
        {
             unVolt = 0;
        }

        DISDASC(0x0b,0x0d,0x9c);

        DISDASC(0x0f,0x0d,0x80+(unVolt%10)*2);
        unVolt /= 10;
        DISDASC(0x0e,0x0d,0x80+(unVolt%10)*2);
        unVolt /= 10;
        DISDASC(0x0d,0x0d,0x80+(unVolt%10)*2);
        unVolt /= 10;
        DISDASC(0x0c,0x0d,0x80+(unVolt%10)*2);
        DISDASC(0x10,0x0d,0xa4);
}

void InitTimer0(void)
{
  TMOD=(TMOD&0xf0)|0x01;//MODE 1
  ET0=1;//
  TH0=0;
  TL0=0;
  TR0=1;//
}

//波特率发生器9600bps
void inittimer1()
{	TMOD=0x21;
	TCON=0x44;
	PCON=0;
	SCON=0x50;
	ES=1;
	TH1=0xfd;
	TL1=0Xfd;
        //TH1=0xfa;
	//TL1=0Xfa;
	TR1=1;
}

void delay_ms(int ms)
{
        int i = 0;
        int j = 0;

        for(i = ms; i > 0; i--)
        {
                j = 1000;
                while(j--)
                {
                }
        }
}
//-------------main function-------------------
void main()
{
    int i = 0;
    int j = 0;
    unsigned char data h = 0;

    INT_1(); /* 初始化函数 */
    CLEAR(); /* 清屏函数 */
    inittimer1(); //初始化定时计数器T1
    InitTimer0(); //初始化定时计数器T0
    ET0 = 0;
    EA = 1; //开中断
    ShowWelcome();//开机画面
    delay_ms(500);
    CLEAR();

    //显示"仪器正在预热"
    ShowHeat();

    while(!bStart)//"bStart = 0"仪器处于预热状态
    {
        INT_1(); /* 初始化函数 */
        //显示"仪器正在预热"
        ShowHeat();
        //CLEAR(); /* 清屏函数 */
        for(i = 0x14; i < 0x17; i++)
        {
             DISHAZIT(14,8*7,i);
             DISHAZIT(15,8*7,i);
             DISHAZIT(16,8*7,i);
             DISHAZIT(17,8*7,i);
             delay_ms(20);
        }
    }
    INT_1(); /* 初始化函数 */
    CLEAR(); /* 清屏函数 */
    CGRAM(); /* 建立CGRAM内字库函数 */
    ShowSample();
    ShowEXG();
    ShowMIN();
    DISDASC(18,0x05,0x9e);//显示"m"
    DISDASC(19,0x05,0x9a);//显示"V"

    ET0 = 1;
    while(1)
    {
         INT_1(); /* 初始化函数 */
         /* 汉字写入(文本方式)*/
         //CLEAR();
         if(unLCDRefresh > 1000)  //由定时器T0实现延时的刷屏操作约为:71秒
         {
              unLCDRefresh = 0;
              CLEAR();
              CGRAM(); /* 建立CGRAM内字库函数 */
              ShowSample();
              ShowEXG();
              ShowMIN();
              DISDASC(18,0x05,0x9e);//显示"m"
              DISDASC(19,0x05,0x9a);//显示"V"
              //DispSampleVoltage(intSmpVal);
         }
         //if(bUpdateSV)
         //{
	      DispSampleVoltage(intSmpVal);//显示采样值
              //bUpdateSV = 0;
         //}
         //if(bUpdateSmpT)
         {
              DispSampleTime(ucSmpT);//显示采样时间
              //bUpdateSmpT = 0;
	 }
         //if(bUpdateMW)
         //{
              DispAmpMultiple(ucMW2);//显示放大倍数
              //bUpdateMW = 0;
	 //}
         //if(bUpdateVolt)
         //{
              DispVoltege(ucVolt);//显示负高压值
             // bUpdateVolt = 0;
         //}
    }
}

void T0_Serve() interrupt 1
{
      TH0=0;// 500次/s,50ms为基本单位
      TL0=0;

      if(bStart) unLCDRefresh ++;
}

void SCom_Serve(void) interrupt 4 using 2 //S_COM Interrupt serve
{
	unsigned char ucDataL = 0;
	unsigned char ucDataH = 0;

	if(RI == 1)//getting message
	{
		ucDataL = SBUF&0x0f;//temporary store the SBUF's low 4 bits data
		ucDataH = SBUF&0xf0;//temporary store the SBUF's high 4 bits data
		switch(ucDataH)
		{
			case 0x10://receive the low 4 bits of Sample Voltage
				intTmpSmpVal = ucDataL;
                                bUpdateSV1 = 1;//
 			    break;
			case 0x20://receive the middle 4 bits of Sample Voltage
                                if(bUpdateSV1)
                                {
				    intTmpSmpVal += ucDataL*0x10;
                                    bUpdateSV2 = 1;
                                }
				break;
			case 0x30://receive the high 4 bits of Sample Voltage
                                if(bUpdateSV1 & bUpdateSV2)
                                {
                                    intTmpSmpVal += ucDataL*0x0100;
                                    intSmpVal = intTmpSmpVal;
				    bUpdateSV = 1;//success in receiving the Value of Sample Voltage
                                    bUpdateSV1 = 0;
                                    bUpdateSV2 = 0;
                                    if(!bStart)//"bStart = 0" means the equipment is in heating.
                                    {
                                         intTestVolt[countVolt++] = intTmpSmpVal;
                                         if(countVolt > 1)
                                         {
                                            countVolt = 0;
                                          }
                                          if(abs(intTestVolt[1] - intTestVolt[0]) < 20)//预热判断
                                          {
                                                countSuccess++;
                                                if(countSuccess > 50)
                                                {
                                                        bStart = 1;//预热结束
                                                }
                                          }
                                          else
                                          {
                                               countSuccess = 0;
                                           }
                                    }
                                }
				break;
			case 0x40://receive the data of measure width (Amplify)
				ucMW2 = ucDataL;
				bUpdateMW = 1;
				break;
			case 0x50://receive the data of the interval of sampling
				ucSmpT = ucDataL;
				bUpdateSmpT = 1;
				break;
			case 0x60://receive the low 4 bits data of minus high voltage
                                ucTmpVolt = ucDataL;
                                bUpdateVolt1 = 1;
                                break;
			case 0x70://recefive the high 4 bits data of minus high voltage
                                if(bUpdateVolt1 == 1)
                                {
				    ucTmpVolt += ucDataL*0x10;
				    bUpdateVolt = 1;//success in receiving the data of minus high voltage
                                    bUpdateVolt1 = 0;
                                    ucVolt = ucTmpVolt;
                                }
				break;
		}
		RI = 0;
	}
}

⌨️ 快捷键说明

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