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

📄 130.c

📁 用单片机控制1620的驱动程序
💻 C
字号:
#include<reg52.h>
#include<math.h>
#include <intrins.h>
#include <absacc.h>

#define DB P2    /*LCD8位数据*/
#define uchar unsigned char
#define uint  unsigned int
#define ulong unsigned long

sbit RS=P1^7;   /*LCD RS*/
sbit RW=P1^6;   /*LCD RW*/
sbit E=P1^5;    /*LCD E */


long data fout;      /*输出频率*/

void delay(int b)    /*延时控制程序*/
{int i;
 for(i=0;i<b;i++);
}

void clearlcd(void)       /*清屏*/
{RS=0;
 RW=0;
 DB=0x01;
 E=1;
 delay(1520);
 E=0;
}


void Readbusy(void)       /*判断是否忙*/
{RS=0;
 RW=1;
 E=1;
 E=1;
 while(DB^7==1)           /*忙一直判断*/
 {if(DB^7==0)break;}      /*不忙跳出*/
 E=0;
}

void Write(unsigned c)    /*写入LED*/
{RS=1;
 RW=0;
 DB=c;
 E=1;
 E=1;
 E=0;
}



void Display(void)       /*显示*/
{int a;
 uchar b;
 b=0x7A;    /* z */
 Readbusy();
 Write(b);
 b=0x48;    /* H */
 Readbusy();
 Write(b);
 a=fout%10000;
 b=0x30|a;
 Readbusy();
 Write(b);
 a=fout%1000/10;
 b=0x30|a;
 Readbusy();
 Write(b);
 a=fout%100/100;
 b=0x30|a;
 Readbusy();
 Write(b);
 a=fout%10/1000;
 b=0x30|a;
 Readbusy();
 Write(b);
 a=fout/10000;
 b=0x30|a;
 Readbusy();
 Write(b);
}

void Setlcd(unsigned c)    /*设置LED*/
{RS=0;
 RW=0;
 DB=c;
 E=1;
 E=1;
 E=0;
}


void Rstlcd(void)         /*初始设置*/
{delay(15000);
 Setlcd(0x38);
 delay(4100);
 Setlcd(0x38);
 delay(4100);
 Setlcd(0x38);
 delay(4100);
 Setlcd(0x38);
 delay(4100);
 Setlcd(0x30);             /*第二行SET Function*/
 delay(160);
 Setlcd(0x08);             /*关显示*/
 delay(160);
 clearlcd();              /*清楚显示*/
 delay(160);
 Setlcd(0x05);            /*输入模式设定*/
 delay(160);
 Setlcd(0x0F);            /*开显示*/
}

void Home(void)          /*光标复位*/
{RS=0;
 RW=0;
 DB=0x02;
 E=1;
 delay(1520);
 E=0;
}


void main(void)         /*主函数*/
{fout=0;
 Rstlcd();
 Readbusy();               /*初始LCD*/
 Setlcd(0x80);
 Readbusy();                  /*判断是否忙*/
 Display();
 while(1)
 {Readbusy();                  /*判断是否忙*/
  Display();                   /*显示*/
  Home();
 }
}

⌨️ 快捷键说明

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