視頻鏈接:https://www.bilibili.com/video/BV1sr4y1C7tH
#include "reg52.h" //此文件中定義了單片機的一些特殊功能寄存器
#include
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
typedef 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;i8;i++) //控制頁數0-7,共8頁
{
Set_page(i);
Set_column(0);
for(j=0;j64;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;i250;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;x128;x++) //正弦曲線
{
read2543(0);
Result = volt / 125030;
y=56-Result;
Draw_dots(x,y,2);
delay(20);
}
Display_picture(BMP); //坐標圖
}
}
審核編輯:湯梓紅
);break;>
聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。
舉報投訴
-
示波器
+關注
關注
113文章
6247瀏覽量
185026 -
寄存器
+關注
關注
31文章
5343瀏覽量
120401 -
Proteus
+關注
關注
79文章
1692瀏覽量
106600
發布評論請先 登錄
相關推薦
基于51單片機的簡易示波器仿真——》Proteus7.5仿真源文件+C語言源工程文件
基于51單片機的簡易示波器仿真——》Proteus7.5仿真源文件+C語言源工程文件;一切來自互聯網,無私分享!
發表于 04-14 10:08
基于AVR的簡易示波器設計
基于AVR的簡易示波器設計:介紹了以AVR單片機ATmega16為核心,采用前端信號調理電路、程控增益放大器以及波形顯示LCD(GDM12864A)實現的一個簡易示波器。并給出該系統設
發表于 05-26 23:41
?97次下載
基于FPGA的雙通道簡易可存儲示波器設計
基于FPGA的雙通道簡易可存儲示波器設計:本文介紹了一種基于FPGA的采樣速度60Mbit/s的雙通道簡易數字示波器設計,能夠實現量程和采樣頻率的自動調整、數據緩存、顯示以及與計算機
發表于 09-29 10:45
?110次下載
評論