視頻鏈接: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; //對數(shù)據(jù)類型進行聲明定義
typedef unsigned char u8;
sbit CLK=P3^3;//定義時鐘信號口
sbit DIN=P3^1;//定義2543數(shù)據(jù)寫入口
sbit DOUT=P3^0;//定義2543數(shù)據(jù)讀取口
sbit CS=P3^2;//定義2543片選信號口
#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;//測量的電壓值
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]={/*-- 調(diào)入了一幅圖像: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()//讀“忙”函數(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(); //對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; //先進行一次空讀操作
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) //設置“頁”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); //規(guī)定顯示的列的位置
}
void SetOnOff(uchar onoff) //顯示開關函數(shù):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) //清屏函數(shù)
{
uchar i,j;
SelectScreen(screen); //0--全屏;1---左半屏;2---右半屏
for(i=0;i8;i++) //控制頁數(shù)0-7,共8頁
{
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); //開顯示
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讀出的數(shù)據(jù)
x_byte=(y?>>3); //計算出該點屬于哪個字節(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); //設置行地址
Set_column(x); //設置列地址
Temp_data=Read_LCD(); //先讀出沒打點前LCD中的數(shù)據(jù)
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;>
聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權轉載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權或者其他違規(guī)問題,請聯(lián)系本站處理。
舉報投訴
-
示波器
+關注
關注
113文章
6246瀏覽量
184940 -
寄存器
+關注
關注
31文章
5343瀏覽量
120348 -
Proteus
+關注
關注
79文章
1692瀏覽量
106573
發(fā)布評論請先 登錄
相關推薦
基于51單片機的簡易示波器仿真——》Proteus7.5仿真源文件+C語言源工程文件
基于51單片機的簡易示波器仿真——》Proteus7.5仿真源文件+C語言源工程文件;一切來自互聯(lián)網(wǎng),無私分享!
發(fā)表于 04-14 10:08
基于AVR的簡易示波器設計
基于AVR的簡易示波器設計:介紹了以AVR單片機ATmega16為核心,采用前端信號調(diào)理電路、程控增益放大器以及波形顯示LCD(GDM12864A)實現(xiàn)的一個簡易示波器。并給出該系統(tǒng)設
發(fā)表于 05-26 23:41
?97次下載
基于FPGA的雙通道簡易可存儲示波器設計
基于FPGA的雙通道簡易可存儲示波器設計:本文介紹了一種基于FPGA的采樣速度60Mbit/s的雙通道簡易數(shù)字示波器設計,能夠?qū)崿F(xiàn)量程和采樣頻率的自動調(diào)整、數(shù)據(jù)緩存、顯示以及與計算機
發(fā)表于 09-29 10:45
?110次下載
評論