首页 行业 查看内容

Proteus:简易示波器

2023-06-14 12:06:04

来源: Harmony&嵌入式学习


【资料图】

视频链接:https://www.bilibili.com/video/BV1sr4y1C7tH

#include "reg52.h" //此文件中定义了单片机的一些特殊功能寄存器#include #define uchar unsigned char#define uint  unsigned int#define ulong unsigned longtypedef unsigned int u16;  //对数据类型进行声明定义typedef unsigned char u8;sbit CLK=P3^3;//定义时钟信号口sbit DIN=P3^1;//定义2543数据写入口sbit DOUT=P3^0;//定义2543数据读取口sbit CS=P3^2;//定义2543片选信号口#define LCD_databus P0 //LCD12864的8位数据口sbit RS=P2^2; //RS为0---命令;1----数据 sbit RW=P2^1; //RW为1---写;0---读 sbit EN=P2^0; //使能端 sbit CS1=P2^4; //片选1低电平有效,控制左半屏 sbit CS2=P2^3; //片选1低电平有效,控制右半屏 ulong volt;//测量的电压值ulong Result;unsigned char code da[]={/*--  文字:  大  --*//*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/0x00,0x00,0x40,0x40,0x40,0x40,0xFF,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x03,0x00,0x01,0x02,0x04,0x08,0x10,0x30,0x20,0x20,0x00};unsigned char code BMP[][64]={/*--  调入了一幅图像:D:Desktop12848坐标.BMP  --*//*--  宽度x高度=128x48  --*/0X00,0X17,0X15,0X1D,0X00,0X02,0XFE,0X06,0X02,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X07,0X04,0X1F,0X00,0X00,0XFF,0X04,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X15,0X15,0X1F,0X00,0X00,0XFF,0X04,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X0E,0X8B,0X0B,0X00,0X00,0XFF,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XC0,0X00,0X0F,0X00,0XC0,0X00,0XFF,0X02,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X02,0X01,0X00,0X78,0X4B,0X7A,0X02,0X02,0X02,0X02,0X02,0X02,0X02,0X02,0XFB,0X02,0X02,0X02,0X02,0X02,0X02,0X02,0X02,0XEA,0XAA,0XBA,0X02,0X02,0X02,0X02,0X02,0X02,0XA2,0XAA,0XFA,0X02,0X02,0X02,0X02,0X02,0X02,0X02,0X3A,0X23,0XFA,0X02,0X02,0X02,0X02,0X02,0X02,0X02,0XBA,0XAB,0XEA,0X02,0X02,0X02,0X02,0X02,0X02,0X02,0XFA,0XAB,0XEA,0X02,0X02,0X02,0X02,0X02,0X02,0X02,0X0A,0X0B,0XFA,0X02,0X02,0X02,0X02,0X02,0X02,0X02,0XFA,0XAB,0XFA,0X02,0X02,0X02,0X02,0X02,0X02,0X02,0XBA,0XFA,0X02,0X02,0X02,0X02,0X02,0X02,0XFA,0X02,0XFB,0X8A,0XFA,0X02,0X02,0X02,0X02,0X02,0X02,0XFA,0X03,0XFA,0X02,0X02,0X02,0X02,0X07,0X00,0X00,0X00,0X00,0X00,0X02,0X02,};void Read_busy()//读“忙”函数-----数据线的最高位DB71则busy{P0=0x00;   RS=0;     RW=1; EN=1;while(P0 & 0x80);EN=0;}void write_LCD_command(uchar value)//写命令函数 {   Read_busy();//对LCD的每次读写都要读忙    RS=0; //选择命令    RW=0; //读操作    LCD_databus=value;   EN=1;//EN由1----0锁存有效数据    _nop_();   _nop_();    EN=0;}void write_LCD_data(uchar value)//写数据函数{   Read_busy();   RS=1; //选择数据    RW=0;   LCD_databus=value;   EN=1;//EN由1----0锁存有效数据    _nop_();   _nop_();   EN=0;}uchar Read_LCD(void)//读数据函数 {uchar value;Read_busy();LCD_databus=0xFF;//先进行一次空读操作 RS=1;RW=1;EN=1;_nop_();_nop_();EN=0;LCD_databus=0xFF;//读取真正的数据 RS=1;RW=1;EN=1;value=LCD_databus;_nop_();_nop_();EN=0;return value; }void Set_page(uchar page)//设置“页”LCD12864共8页,一页是8行点阵点{  page=0xb8|page; //页的首地址为0xB8  write_LCD_command(page);}void Set_line(uchar startline)  //设置显示的起始行   {  startline=0xC0|startline;     //起始行地址为0xC0   write_LCD_command(startline); //设置从哪行开始:共0--63;一般从0 行开始显示}void Set_column(uchar column)//设置显示的列{  column=column &0x3f; //列的最大值为64  column= 0x40|column; //列的首地址为0x40   write_LCD_command(column);//规定显示的列的位置 }void SetOnOff(uchar onoff)//显示开关函数:0x3E是关显示,0x3F是开显示   {onoff=0x3e|onoff; //onoff:1---开显示;0---关显示write_LCD_command(onoff);}void SelectScreen(uchar screen)//选择屏幕 {     switch(screen)   {     case 0: CS1=0;CS2=0;break; //全屏          case 1: CS1=0;CS2=1;break;//左半屏             case 2: CS1=1;CS2=0;break;//右半屏            default:break;    }}void ClearScreen(uchar screen)//清屏函数  {      uchar i,j;     SelectScreen(screen);//0--全屏;1---左半屏;2---右半屏  for(i=0;i<8;i++) //控制页数0-7,共8页 {        Set_page(i);Set_column(0);      for(j=0;j<64;j++)   //控制列数0-63,共64列  {          write_LCD_data(0x00); //写入0,地址指针自加1       }     } }void InitLCD() //LCD的初始化  { SetOnOff(1); //开显示SelectScreen(0);ClearScreen(0);//清屏Set_line(0); //开始行:0}void Draw_dots(uchar x,uchar y,uchar color){uchar x_byte;uchar x_bit; uchar Temp_data;//暂时存放从LCD读出的数据 x_byte=(y>>3);  //计算出该点属于哪个字节 x_bit=y-(x_byte<<3);//属于字节的哪一位?if(x>63)//x>63则显示在右半屏 {SelectScreen(2);x=x-64;}else//显示在左半屏 {SelectScreen(1); }Set_page(x_byte);//设置行地址 Set_column(x);//设置列地址 Temp_data=Read_LCD();//先读出没打点前LCD中的数据 switch(color){case 0x01 : Temp_data &= ~(1<>=1;volt=ad;//取走转换结果volt=volt*1221;//例子的满量程为5V,转换分辩率为12位(2的12次方=4096) 。即最大值是255,5/4096=1221mV,即例子中的1V代表实际1221mV        }void delay(uchar ms) {  // 延时子程序 uchar i; while(ms--) {   for(i = 0;i<250;i++);  } }void main(){  uchar x,y;  InitLCD();//初始12864    ClearScreen(0);//清屏  Set_line(0);//显示开始行Display_picture(BMP);  //坐标图Display_HZ(1,0,0,da);Display_HZ(2,0,2,da);while(1){for(x=12;x<128;x++)//正弦曲线{read2543(0);  Result = volt / 125030;y=56-Result;Draw_dots(x,y,2);delay(20);}Display_picture(BMP);  //坐标图}}
审核编辑:汤梓红);break;>

关键词:

最新新闻
回顶部