標題: 用51單片機和12864設計的簡易示波器 [打印本頁]
作者: 51黑ren 時間: 2015-12-25 03:38
標題: 用51單片機和12864設計的簡易示波器
源程序#include <reg51.h>
#include <intrins.h>
#include <ADC0808.c>
sbit DI=P2^2; // 數據\指令選擇
sbit RW=P2^1; // 讀\寫選擇
sbit E=P2^0; // 讀\寫使能
sbit CS1=P2^4; // 片選1
sbit CS2=P2^3; // 片選2
sbit busy=P1^7;
sbit jia=P3^7;
sbit jian=P3^3;
sbit jia1=P3^0;
sbit jian1=P3^1;
unsigned int i;
unsigned char ye,lei,shu;
unsigned char a[94];
char code t[]={
0x00,0x00,0x08,0x00,0x04,0x00,0x02,0x00,0x01,0x80,0x40,0x60,0x80,0x00,0x7F,0xFF,//小
0x00,0x00,0x00,0x20,0x00,0x40,0x00,0x80,0x01,0x00,0x06,0x00,0x00,0x00,0x00,0x00,
0x00,0x80,0x00,0x80,0x00,0x82,0x00,0x82,0x00,0x82,0x40,0x82,0x80,0x82,0x7F,0xE2,//子
0x00,0xA2,0x00,0x92,0x00,0x8A,0x00,0x86,0x00,0x80,0x00,0xC0,0x00,0x80,0x00,0x00,
0x00,0x40,0x00,0x60,0x3F,0x5E,0x01,0x48,0x01,0x48,0xFF,0xFF,0x11,0x48,0x21,0x4C,//制
0x1F,0x68,0x00,0x40,0x07,0xF8,0x40,0x00,0x80,0x00,0x7F,0xFF,0x00,0x00,0x00,0x00,
0x00,0x80,0x00,0x40,0x00,0x20,0xFF,0xF8,0x00,0x87,0x00,0x40,0x00,0x30,0x00,0x0F,//作
0xFF,0xF8,0x08,0x88,0x08,0x88,0x08,0xC8,0x0C,0x88,0x08,0x0C,0x00,0x08,0x00,0x00,
};
void checkstate()
{
//bit dat;
DI=0;
RW=1;
//P1=0x00;
do
{
E=1;
E=0;
//僅當第7位為0時才可操作(判別busy信號)
}while(busy==1);
}
void writecommand(unsigned char command) //寫命令
{
checkstate();
DI=0;
RW=0;
P1=command;
E=1;
E=0;
}
void writedate(unsigned char date) //寫數據
{
checkstate();
DI=1;
RW=0;
P1=date;
E=1;
E=0;
}
void pianxuan(unsigned int i)
{
if(i==1)
CS1=0,CS2=1;
if(i==2)
CS1=1,CS2=0;
if(i==3)
CS1=0,CS2=0;
}
void cleanscreen() //清屏
{
unsigned char page,i;
for(page=0xb8;page<0xc0;page++)
{
writecommand(page);
writecommand(0x40);
for(i=0;i<64;i++)
writedate(0x00);
}
}
void init(void) //開顯示,起始行0行
{
writecommand(0xc0);
writecommand(0x3f);
}
void delay_50us(uint t)
{
uchar j;
for(;t>0;t--)
for(j=19;j>0;j--)
;
}
void shuju()
{
pianxuan(i);
writecommand(ye);
writecommand(lei);
writedate(shu);
}
void qing()
{
uchar i;
for(i=0xb8;i<=0xbf;i++)
{
ye=i;
shu=0x00;
shuju();
}
}
void main()
{
uint r,j,g=0,q,dianya=1,k,p;
uchar U,m,l;
pianxuan(3);
cleanscreen();
init();
pianxuan(2);
l=0xb8;
for(k=0;k<4;k++,l=l+0x02)
{
ye=l;
lei=0x70;
for(r=0;r<16;r++)
{
shu=t[2*r+1+32*k];
shuju();
lei++;
}
ye=l+0x01;
lei=0x70;
for(r=0;r<16;r++)
{
shu=t[2*r+32*k];
shuju();
lei++;
}
}
while(1)
{
uchar d1,d2,d3,d4,d5;
aaa:do
{
adc();
}while((AD!=128)&&(AD!=129)&&(AD!=130));
U=AD;
adc();
if(U>AD)
goto aaa;
while(jia==0)
{
while(jia==0);
g=g+1;
}
while(jian==0)
{
while(jian==0);
if(g!=0) g=g-1;
}
while(jia1==0)
{
while(jia1==0);
dianya=dianya+1;
}
while(jian1==0)
{
while(jian1==0);
if(dianya!=1) dianya=dianya-1;
}
for(j=0;j<94;j++) //AD采樣
{
adc();
a[j]=AD;
delay_50us(g);
}
lei=0x40;
for(r=0,j=0;r<94;r++,j++)
{
if(j<64) i=1;
if(j==64) lei=0x40;
if(j>=64)i=2;
qing(); //清掉之前的內容
AD=a[j]*0.196/dianya; //計算在12864的電壓值
if(AD<=7) ye=0xbf,shu=(0x80>>AD);
else if(AD<=15)ye=0xbe,shu=0x80>>(AD-8);
else if(AD<=23) ye=0xbd,shu=0x80>>(AD-16);
else if(AD<=31) ye=0xbc,shu=0x80>>(AD-24);
else if(AD<=39) ye=0xbb,shu=0x80>>(AD-32);
else if(AD<=47) ye=0xba,shu=0x80>>(AD-40);
else if(AD<=55) ye=0xb9,shu=0x80>>(AD-48);
else if(AD<=63)ye=0xb8,shu=0x80>>(AD-56);
if(r==0)
{
d1=shu;
d2=ye;
}
if(r!=0)
{
d3=shu;
d4=ye;
if(ye==d2)
{
if(shu>d1)
{
d5=shu;
d5=d5>>1;
while(d5!=d1)
{d5=d5>>1;
shu=shu|(shu>>1);}
}
if(shu<d1)
{
d5=shu;
d5=d5<<1;
while(d5!=d1)
{d5=d5<<1;shu=shu|(shu<<1);}
}
}
if(ye<d2)
{
for(q=0;q<7;q++)
{
shu=shu|(shu<<1);
}
shuju();
ye++;
while(ye<d2) {shu=0xff,shuju(),ye++;}
if(ye==d2){
shu=0x01;
if(shu<d1)
{
d5=shu;
d5=d5<<1;
while(d5!=d1)
{d5=d5<<1;shu=shu|(shu<<1);}
}
}
}
if(ye>d2)
{
for(q=0;q<7;q++)
{
shu=shu|(shu>>1);
}
shuju();
ye--;
while(ye>d2) {shu=0xff,shuju(),ye--;}
if(ye==d2){
shu=0x80;
if(shu>d1)
{
d5=shu;
d5=d5>>1;
while(d5!=d1)
{d5=d5>>1;shu=shu|(shu>>1);}
}
}
}
}
if(r!=0)
{
d1=d3;
d2=d4;
}
shuju();
if(lei!=0x7f) lei++;
}
}
}
作者: htzsz 時間: 2016-11-14 15:47
樓主,能不能把仿真和源程序發出來學習學習呀!
作者: 舊時光wolf 時間: 2017-5-17 23:44
樓主,求仿真和全部代碼
作者: 13080788458 時間: 2017-6-1 21:11
樓主,可以把那個電路圖再發一遍嗎看不太清,謝謝了!
作者: liyong362 時間: 2018-5-15 19:02
樓主,可以上傳一下仿真和代碼嗎
歡迎光臨 (http://www.zg4o1577.cn/bbs/) |
Powered by Discuz! X3.1 |
主站蜘蛛池模板:
一区二区三区在线观看视频
|
国产精品1区2区3区
男女啪啪高潮无遮挡免费动态
|
亚洲精品在线观
|
日韩成人在线免费观看
|
国产精品久久久久久久久免费樱桃
|
国产在线精品一区二区三区
|
一区二区国产精品
|
亚洲成人精品影院
|
视频一区二区中文字幕
|
色综合天天天天做夜夜夜夜做
|
风间由美一区二区三区在线观看
|
97视频在线免费
|
国产精品永久免费观看
|
免费一级欧美在线观看视频
|
国产在线观看一区二区三区
|
天堂免费
|
久久精品国产久精国产
|
国产一区二区三区视频免费观看
|
日韩欧美亚洲
|
日韩一级二级片
|
精品国产欧美一区二区三区不卡
|
黄色网址在线免费观看
|
精品国产伦一区二区三区观看方式
|
狠狠影院
|
亚洲精品68久久久一区
|
日韩a在线
|
久久99网站
|
国产激情一区二区三区
|
欧美日韩一区二区三区视频
|
欧美一区二区久久
|
久久久久无码国产精品一区
|
免费一级毛片
|
免费看91
|
色婷婷久久综合
|
青春草国产
|
久色网
|
国产资源一区二区三区
|
天天操夜夜爽
|
国产一区精品在线
|
国产精品成人一区二区三区
|
情侣酒店偷拍一区二区在线播放
|