視頻鏈接:https://www.bilibili.com/video/BV1sr4y1C7tH
#include "reg52.h" //此文件中定義了單片機(jī)的一些特殊功能寄存器
#include
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
typedef unsigned int u16; //對(duì)數(shù)據(jù)類型進(jìn)行聲明定義
typedef unsigned char u8;
sbit CLK=P3^3;//定義時(shí)鐘信號(hào)口
sbit DIN=P3^1;//定義2543數(shù)據(jù)寫入口
sbit DOUT=P3^0;//定義2543數(shù)據(jù)讀取口
sbit CS=P3^2;//定義2543片選信號(hào)口
#define LCD_databus P0 //LCD12864的8位數(shù)據(jù)口
sbit RS=P2^2; //RS為0---命令;1----數(shù)據(jù)
sbit RW=P2^1; //RW為1---寫;0---讀
sbit EN=P2^0; //使能端
sbit CS1=P2^4; //片選1低電平有效,控制左半屏
sbit CS2=P2^3; //片選1低電平有效,控制右半屏
ulong volt;//測(cè)量的電壓值
ulong Result;
unsigned char code da[]={/*-- 文字: 大 --*/
/*-- 楷體_GB231212; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬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]={/*-- 調(diào)入了一幅圖像:D:Desktop12848坐標(biāo).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()//讀“忙”函數(shù)-----數(shù)據(jù)線的最高位DB71則busy
{
P0=0x00;
RS=0;
RW=1;
EN=1;
while(P0 & 0x80);
EN=0;
}
void write_LCD_command(uchar value) //寫命令函數(shù)
{
Read_busy(); //對(duì)LCD的每次讀寫都要讀忙
RS=0; //選擇命令
RW=0; //讀操作
LCD_databus=value;
EN=1; //EN由1----0鎖存有效數(shù)據(jù)
_nop_();
_nop_();
EN=0;
}
void write_LCD_data(uchar value)//寫數(shù)據(jù)函數(shù)
{
Read_busy();
RS=1; //選擇數(shù)據(jù)
RW=0;
LCD_databus=value;
EN=1; //EN由1----0鎖存有效數(shù)據(jù)
_nop_();
_nop_();
EN=0;
}
uchar Read_LCD(void) //讀數(shù)據(jù)函數(shù)
{
uchar value;
Read_busy();
LCD_databus=0xFF; //先進(jìn)行一次空讀操作
RS=1;
RW=1;
EN=1;
_nop_();
_nop_();
EN=0;
LCD_databus=0xFF; //讀取真正的數(shù)據(jù)
RS=1;
RW=1;
EN=1;
value=LCD_databus;
_nop_();
_nop_();
EN=0;
return value;
}
void Set_page(uchar page) //設(shè)置“頁(yè)”LCD12864共8頁(yè),一頁(yè)是8行點(diǎn)陣點(diǎn)
{
page=0xb8|page; //頁(yè)的首地址為0xB8
write_LCD_command(page);
}
void Set_line(uchar startline) //設(shè)置顯示的起始行
{
startline=0xC0|startline; //起始行地址為0xC0
write_LCD_command(startline); //設(shè)置從哪行開(kāi)始:共0--63;一般從0 行開(kāi)始顯示
}
void Set_column(uchar column) //設(shè)置顯示的列
{
column=column &0x3f; //列的最大值為64
column= 0x40|column; //列的首地址為0x40
write_LCD_command(column); //規(guī)定顯示的列的位置
}
void SetOnOff(uchar onoff) //顯示開(kāi)關(guān)函數(shù):0x3E是關(guān)顯示,0x3F是開(kāi)顯示
{
onoff=0x3e|onoff; //onoff:1---開(kāi)顯示;0---關(guān)顯示
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) //清屏函數(shù)
{
uchar i,j;
SelectScreen(screen); //0--全屏;1---左半屏;2---右半屏
for(i=0;i8;i++) //控制頁(yè)數(shù)0-7,共8頁(yè)
{
Set_page(i);
Set_column(0);
for(j=0;j64;j++) //控制列數(shù)0-63,共64列
{
write_LCD_data(0x00); //寫入0,地址指針自加1
}
}
}
void InitLCD() //LCD的初始化
{
SetOnOff(1); //開(kāi)顯示
SelectScreen(0);
ClearScreen(0); //清屏
Set_line(0); //開(kāi)始行:0
}
void Draw_dots(uchar x,uchar y,uchar color)
{
uchar x_byte;
uchar x_bit;
uchar Temp_data; //暫時(shí)存放從LCD讀出的數(shù)據(jù)
x_byte=(y?>>3); //計(jì)算出該點(diǎn)屬于哪個(gè)字節(jié)
x_bit=y-(x_byte<3); //屬于字節(jié)的哪一位?
if(x?>63) //x>63則顯示在右半屏
{
SelectScreen(2);
x=x-64;
}
else //顯示在左半屏
{
SelectScreen(1);
}
Set_page(x_byte); //設(shè)置行地址
Set_column(x); //設(shè)置列地址
Temp_data=Read_LCD(); //先讀出沒(méi)打點(diǎn)前LCD中的數(shù)據(jù)
switch(color)
{
case 0x01 : Temp_data &= ~(1>=1;
volt=ad;//取走轉(zhuǎn)換結(jié)果
volt=volt*1221;//例子的滿量程為5V,轉(zhuǎn)換分辯率為12位(2的12次方=4096) 。即最大值是255,5/4096=1221mV,即例子中的1V代表實(shí)際1221mV
}
void delay(uchar ms)
{ // 延時(shí)子程序
uchar i;
while(ms--)
{
for(i = 0;i250;i++);
}
}
void main()
{
uchar x,y;
InitLCD(); //初始12864
ClearScreen(0); //清屏
Set_line(0); //顯示開(kāi)始行
Display_picture(BMP); //坐標(biāo)圖
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); //坐標(biāo)圖
}
}
審核編輯:湯梓紅
);break;>
聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。
舉報(bào)投訴
-
示波器
+關(guān)注
關(guān)注
113文章
6167瀏覽量
184327 -
寄存器
+關(guān)注
關(guān)注
31文章
5295瀏覽量
119838 -
Proteus
+關(guān)注
關(guān)注
79文章
1692瀏覽量
106294
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
求基于單片機(jī)的簡(jiǎn)易示波器的課程設(shè)計(jì)包括proteus仿真
求基于單片機(jī)的簡(jiǎn)易示波器的課程設(shè)計(jì)包括proteus仿真
發(fā)表于 06-22 10:20
基于51單片機(jī)的簡(jiǎn)易示波器仿真——》Proteus7.5仿真源文件+C語(yǔ)言源工程文件
基于51單片機(jī)的簡(jiǎn)易示波器仿真——》Proteus7.5仿真源文件+C語(yǔ)言源工程文件;一切來(lái)自互聯(lián)網(wǎng),無(wú)私分享!
發(fā)表于 04-14 10:08
基于AVR的簡(jiǎn)易示波器設(shè)計(jì)
基于AVR的簡(jiǎn)易示波器設(shè)計(jì):介紹了以AVR單片機(jī)ATmega16為核心,采用前端信號(hào)調(diào)理電路、程控增益放大器以及波形顯示LCD(GDM12864A)實(shí)現(xiàn)的一個(gè)簡(jiǎn)易示波器。并給出該系統(tǒng)設(shè)
發(fā)表于 05-26 23:41
?97次下載
基于FPGA的雙通道簡(jiǎn)易可存儲(chǔ)示波器設(shè)計(jì)
基于FPGA的雙通道簡(jiǎn)易可存儲(chǔ)示波器設(shè)計(jì):本文介紹了一種基于FPGA的采樣速度60Mbit/s的雙通道簡(jiǎn)易數(shù)字示波器設(shè)計(jì),能夠?qū)崿F(xiàn)量程和采樣頻率的自動(dòng)調(diào)整、數(shù)據(jù)緩存、顯示以及與計(jì)算機(jī)
發(fā)表于 09-29 10:45
?110次下載
基于STM32的簡(jiǎn)易示波器設(shè)備驅(qū)動(dòng)的研究
基于STM32的簡(jiǎn)易示波器設(shè)備驅(qū)動(dòng)的研究
發(fā)表于 11-06 17:04
?68次下載
簡(jiǎn)易數(shù)字存儲(chǔ)示波器設(shè)計(jì)
設(shè)計(jì)一簡(jiǎn)易數(shù)字存儲(chǔ)示波器(簡(jiǎn)易DSO)。
發(fā)表于 03-18 15:20
?412次下載
基于stm32mini開(kāi)發(fā)板的簡(jiǎn)易函數(shù)發(fā)生器和簡(jiǎn)易示波器
基于stm32 mini開(kāi)發(fā)板的簡(jiǎn)易示波器
發(fā)表于 01-17 10:01
?35次下載
基于LabVIEW的簡(jiǎn)易虛擬示波器設(shè)計(jì)
基于LabVIEW的簡(jiǎn)易虛擬示波器設(shè)計(jì)方法。
發(fā)表于 04-06 15:33
?126次下載
評(píng)論