为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

串口打印

2017-11-22 9页 doc 20KB 30阅读

用户头像

is_995397

暂无简介

举报
串口打印串口打印 #include #include #define uint unsigned int #define uchar unsigned char sbit dula=P2^6; sbit wela=P2^7; sbit sck=P2^1; sbit sda=P2^0; uchar js,flag1,num; uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71...
串口打印
串口打印 #include #include #define uint unsigned int #define uchar unsigned char sbit dula=P2^6; sbit wela=P2^7; sbit sck=P2^1; sbit sda=P2^0; uchar js,flag1,num; uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; void de() { uint i=0,j=0; for(i=4;i>0;i--) for(j=110;j>0;j--); } void display(uchar num) { uchar bai=0,shi=0,ge=0; bai=num/100; num=num%100; shi=num/10; ge=num%10; P0=0xfe; wela=1; wela=0; P0=table[bai]; dula=1; dula=0; de(); P0=table[shi]; dula=1; dula=0; P0=0xfd; wela=1; wela=0; de(); P0=table[ge]; dula=1; dula=0; P0=0xfb; wela=1; wela=0; de(); P0=0x00; dula=1; dula=0; P0=0xff; wela=1; wela=0; } void delay() {;;} void iniit() { sck=1; delay(); sda=1; delay(); } void start() { sck=1; delay(); sda=1; delay(); sda=0; delay(); } void stop() { sck=1; delay(); sda=0; delay(); sda=1; delay(); } void response() { uchar i=0; sck=1; delay(); if((sda==1)&&(i<255)) i++; sck=0; delay(); } void writebyte(uchar date) { uchar i,k; k=date; for(i=8;i>0;i--) { k=k<<1; sck=0; delay(); sda=CY; delay(); sck=1; delay(); } sck=0; delay(); sda=1; delay(); } uchar readbyte() { uchar i=0,k=0; sck=0; delay(); sda=1; delay(); for(i=8;i>0;i--) { sck=1; delay(); k=(k<<1)|sda; sck=0; delay(); } sda=1; delay(); return k; } uchar readadd() { uchar p; start(); writebyte(0x90); response(); writebyte(0x00); response(); start(); writebyte(0x91); response(); p=readbyte(); stop(); return p; } void main() { uchar a,flag2; iniit(); a=readadd(); TMOD=0x21; TH1=0xfd; TL1=0xfd; TR1=1; SCON=0x50; EA=1; ES=1; TH0=(65536-46080)/256; TL0=(65536-46080)%256; ET0=1; while(1) { if(flag1==1) { flag1=0; TI=1; ES=0; if(js==0x01) { puts("Turn on the AD!\n"); flag2=1; TR0=1; } else if(js==0x10) { puts("Turn off the AD!\n"); flag2=0; TR0=0; } else puts("ERROR!\n"); while(!TI); TI=0; ES=1; } if(flag2==1) { a=readadd(); display(a); } if(num==20) { num=0; TI=1; ES=0; a=readadd(); printf("the votage is %u!\n",a); while(!TI); TI=0; ES=1; } } } void chuankou() interrupt 4 { if(RI==1) { RI=0; js=SBUF; flag1=1; } } void t0() interrupt 1 { TH0=(65536-46080)/256; TL0=(65536-46080)%256; num++;
/
本文档为【串口打印】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索