基于51单片机的电子示波器的设计.zip

  • AlpcaSun
    了解作者
  • C/C++
    开发工具
  • 60.5KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 2 积分
    下载积分
  • 0
    下载次数
  • 2022-01-23 21:26
    上传日期
基于89C51单片机的电子示波器源码,C语言编写,用Keil5及以上版本打开
基于51单片机的电子示波器的设计.zip
  • 1-程序
  • STARTUP.LST
    13.7KB
  • main.c
    11.6KB
  • 程序.hex
    13KB
  • 程序.plg
    2.4KB
  • 程序.lnp
    56B
  • STARTUP.A51
    6.2KB
  • 程序.M51
    37.8KB
  • 程序.uvgui.Administrator
    82.3KB
  • STARTUP.OBJ
    751B
  • 程序.uvproj
    13.7KB
  • main.LST
    23.4KB
  • 程序.uvopt
    5.3KB
  • 程序
    35.6KB
  • main.OBJ
    42.2KB
  • stc12c5a.H
    17.3KB
内容介绍
#include <STC12c5a.H> #include<intrins.h> #include<math.h> sbit RS=P2^5; //并行的指令/数据选择信号, H数据, L命令 sbit RW=P2^6; //并行读写选择信号, H读, L写 sbit E=P2^7; //并行使能端, H有效, L无效 sbit led=P1^0; sbit jiakey=P3^0; sbit jiankey=P3^1; sbit ledkey=P3^2; #define LcdData P0 unsigned char dati=0; unsigned char dat[100]; unsigned char over=0; unsigned int temp=0; unsigned char mode=0; unsigned int delnop=0; ////////////////////////////////////// unsigned char Lcd_CheckBusy(void) { unsigned char Busy; LcdData=0xff; RS=0; RW=1; E=1; _nop_(); Busy=LcdData&0x80; E=0; return Busy; } /********************************* 向LCD写入字节数据 **********************************/ void Lcd_WriteData(unsigned char Data) { while(Lcd_CheckBusy()); RS=1; RW=0; E=0; _nop_(); _nop_(); LcdData=Data; E=1; _nop_(); _nop_(); E=0; } /*********************************** 从LCD中读出数据 ************************************/ unsigned char Lcd_ReadData(void) { unsigned char Temp; while(Lcd_CheckBusy()); LcdData=0xff; RS=1; RW=1; E=1; _nop_(); Temp=LcdData; E=0; return Temp; } /************************************* 想LCD中写入指令代码 **************************************/ void Lcd_WriteCmd(unsigned char CmdCode) { while(Lcd_CheckBusy()); RS=0; RW=0; E=0; _nop_(); _nop_(); LcdData=CmdCode; _nop_(); _nop_(); E=1; _nop_(); _nop_(); E=0; } /************************************** 为加速逻辑运算而设置的掩码表,这是以牺牲空间而换取时间的办法 ***************************************/ code unsigned int LcdMaskTab[]={0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000}; /*************************************** 向LCD指定坐标写入一个象素,象素颜色有两种,0代表白(无显示),1代表黑(有显示) ****************************************/ void Lcd_PutPixel(unsigned char x,unsigned char y,unsigned char Color) { unsigned char z,w; unsigned int Temp; if(x>=128||y>=64) return; Color=Color%2; w=15-x%16;//确定对这个字的第多少位进行操作 x=x/16;//确定为一行上的第几字 if(y<32) //如果为上页 z=0x80; else //否则如果为下页 z=0x88; y=y%32; //EA=0; Lcd_WriteCmd(0x36); Lcd_WriteCmd(y+0x80); //行地址 Lcd_WriteCmd(x+z); //列地址 Temp=Lcd_ReadData();//先空读一次 Temp=(unsigned int)Lcd_ReadData()<<8;//再读出高8位 Temp|=(unsigned int)Lcd_ReadData();//再读出低8位 //EA=1; if(Color==1) //如果写入颜色为1 Temp|=LcdMaskTab[w];//在此处查表实现加速 else //如果写入颜色为0 Temp&=~LcdMaskTab[w];//在此处查表实现加速 //EA=0; Lcd_WriteCmd(y+0x80); //行地址 Lcd_WriteCmd(x+z); //列地址 Lcd_WriteData(Temp>>8);//先写入高8位,再写入低8位 Lcd_WriteData(Temp&0x00ff); Lcd_WriteCmd(0x30); //EA=1; } /***************************************** 清除Lcd全屏,如果清除模式Mode为0,则为全屏清除为颜色0(无任何显示) 否则为全屏清除为颜色1(全屏填充显示) ******************************************/ void Lcd_Clear(unsigned char Mode) { unsigned char x,y,ii; unsigned char Temp; if(Mode%2==0) Temp=0x00; else Temp=0xff; Lcd_WriteCmd(0x36);//扩充指令 绘图显示 for(ii=0;ii<9;ii+=8) for(y=0;y<0x20;y++) for(x=0;x<8;x++) { //EA=0; Lcd_WriteCmd(y+0x80); //行地址 Lcd_WriteCmd(x+0x80+ii); //列地址 Lcd_WriteData(Temp); //写数据 D15-D8 Lcd_WriteData(Temp); //写数据 D7-D0 //EA=1; } Lcd_WriteCmd(0x30); } /**************************************** LCD初始化 *****************************************/ void Lcd_Reset() { Lcd_WriteCmd(0x30); //选择基本指令集 Lcd_WriteCmd(0x0c); //开显示(无游标、不反白) Lcd_WriteCmd(0x01); //清除显示,并且设定地址指针为00H Lcd_WriteCmd(0x06); //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位 } ////////////////////////////////////// void InitADC() { P1ASF=0X80; ADC_RES=0; ADC_CONTR=0xef; EADC=1; } void adc_isr() interrupt 5 using 1 { ADC_CONTR=0xef; if(over==0) { temp=delnop; while(temp) { temp--; } dat[dati]=ADC_RES; dati++; if(dati>100) { dati=0; over=1; } } } ////////////////////////////////////// void disp_0(unsigned char x,unsigned char y) { Lcd_PutPixel(x+1,y+1,1); Lcd_PutPixel(x+1,y+2,1); Lcd_PutPixel(x+1,y+3,1); Lcd_PutPixel(x+2,y+0,1); Lcd_PutPixel(x+2,y+4,1); Lcd_PutPixel(x+3,y+1,1); Lcd_PutPixel(x+3,y+2,1); Lcd_PutPixel(x+3,y+3,1); } void disp_1(unsigned char x,unsigned char y) { Lcd_PutPixel(x+1,y+1,1); Lcd_PutPixel(x+1,y+4,1); Lcd_PutPixel(x+2,y+0,1); Lcd_PutPixel(x+2,y+1,1); Lcd_PutPixel(x+2,y+2,1); Lcd_PutPixel(x+2,y+3,1); Lcd_PutPixel(x+2,y+4,1); Lcd_PutPixel(x+3,y+4,1); } void disp_2(unsigned char x,unsigned char y) { Lcd_PutPixel(x+1,y+0,1); Lcd_PutPixel(x+1,y+2,1); Lcd_PutPixel(x+1,y+3,1); Lcd_PutPixel(x+1,y+4,1); Lcd_PutPixel(x+2,y+0,1); Lcd_PutPixel(x+2,y+2,1); Lcd_PutPixel(x+2,y+4,1); Lcd_PutPixel(x+3,y+0,1); Lcd_PutPixel(x+3,y+1,1); Lcd_PutPixel(x+3,y+2,1); Lcd_PutPixel(x+3,y+4,1); } void disp_3(unsigned char x,unsigned char y) { Lcd_PutPixel(x+1,y+0,1); Lcd_PutPixel(x+1,y+2,1); Lcd_PutPixel(x+1,y+4,1); Lcd_PutPixel(x+2,y+0,1); Lcd_PutPixel(x+2,y+2,1); Lcd_PutPixel(x+2,y+4,1); Lcd_PutPixel(x+3,y+0,1); Lcd_PutPixel(x+3,y+1,1); Lcd_PutPixel(x+3,y+2,1); Lcd_PutPixel(x+3,y+3,1); Lcd_PutPixel(x+3,y+4,1); } void disp_4(unsigned char x,unsigned char y) { Lcd_PutPixel(x+1,y+0,1); Lcd_PutPixel(x+1,y+1,1); Lcd_PutPixel(x+1,y+2,1); Lcd_PutPixel(x+2,y+2,1); Lcd_PutPixel(x+3,y+0,1); Lcd_PutPixel(x+3,y+1,1); Lcd_PutPixel(x+3,y+2,1); Lcd_PutPixel(x+3,y+3,1); Lcd_PutPixel(x+3,y+4,1); } void disp_5(unsigned char x,unsigned char y) { Lcd_PutPixel(x+1,y+0,1); Lcd_PutPixel(x+1,y+1,1); Lcd_PutPixel(x+1,y+2,1); Lcd_PutPixel(x+1,y+4,1); Lcd_PutPixel(x+2,y+0,1); Lcd_PutPixel(x+2,y+2,1); Lcd_PutPixel(x+2,y+4,1); Lcd_PutPixel(x+3,y+0,1); Lcd_PutPixel(x+3,y+2,1); Lcd_PutPixel(x+3,y+3,1); Lcd_PutPixel(x+3,y+4,1); } void disp_p(unsigned char x,unsigned char y) { Lcd_PutPixel(x+0,y+0,1); Lcd_PutPixel(x+1,y+0,1); Lcd_PutPixel(x+1,y+1,1); Lcd_PutPixel(x+2,y+0,1); Lcd_PutPixel(x+2,y+1,1); Lcd_PutPixel(x+2,y+2,1); Lcd_PutPixel(x+3,y+0,1); Lcd_PutPixel(x+3,y+1,1); Lcd_PutPixel(x+4,y+0,1); } void disp_k(unsigned char x,unsigned char y) { Lcd_PutPixel(x+0,y+0,1); Lcd_PutPixel(x+0,y+1,1); Lcd_PutPixel(x+0,y+2,1); Lcd_PutPixel(x+0,y+3,1); Lcd_PutPixel(x+0,y+4,1); Lcd_PutPixel(x+1,y+2,1); Lcd_PutPixel(x+2,y+1,1); Lcd_PutPixel(x+2,y+3,1); Lcd_PutPixel(x+3,y+0,1); Lcd_PutPixel(x+3,y+4,1); } void disp_hz(unsigned char x,unsigned char y) { Lcd_PutPixel(x+0,y+0,1); Lcd_PutPixel(x+0,y+1,1); Lcd_PutPixel(x+0,y+2,1); Lcd_PutPixel(x+0,y+3,1); Lcd_PutPixel(x+0,y+4,1); Lcd_PutPixel(x+1,y+2,1); Lcd_PutPixel(x+2,y+0,1); Lcd_PutPixel(x+2,y+1,1); Lcd_PutPixel(x+2,y+2,1); Lcd_PutPixel(x+2,y+3,1); Lcd_PutPixel(x+2,y+4,1); Lcd_PutPixel(x+4,y+1,1); Lcd_PutPixel(x+4,y+3,1); Lcd_PutPixel(x+4,y+4,1); Lcd_PutPixel(x+5,y+1,1); Lcd_PutPixel(x+5,y+2,1); Lcd_PutPixel(x+5,y+4,1); } void disp_ledon(unsigned char x,unsigned char y) { Lcd_PutPixel(x+1,y+0,1); Lcd_PutPixel(x+1,y+1,1); Lcd_PutPixel(x+1,y+2,1); Lcd_PutPixel(x+1,y+3,1); Lcd_PutPixel(x+1,y+4,1); Lcd_PutPixel(x+2,y+1,1); Lcd_PutPixel(x+2,y+2,1); Lcd_PutPixel(x+2,y+3,1); Lcd_PutPixel(x+3,y+0,1); Lcd_PutPixel(x+3,y+4,1); Lcd_PutPixel(x+4,y+2,1); } void disp_ledoff(unsigned char x,unsigned char y) { Lcd_PutPixel(x+1,y+0,1); Lcd_PutPixel(x+1,y+1,1); Lcd_PutPixel(x+1,y+2,1); Lcd_PutPixel(x+1,y+3,1); Lcd_PutPixel(x+1,y+4,1); Lcd_PutPixel(x+2,y+1,1); Lcd_PutPixel(x+2,y+2,1); Lcd_PutPixel(x+2,y+3,1); } void clr(unsigned char starx,unsigned char stary,unsigned char endx,unsigned char endy) { char x=0; char y=0; for(x=st
评论
    相关推荐