led流水灯的视频呵呵:
视频地址:http://player.youku.com/player.php/sid/XNzExMTY5MTcy/v.swf
牛刀小试6.4 步进电机循环来回转动:
代码如下、如有不足,麻烦指正!
#include<stc89.h> sbit mota = P1^5; sbit motb = P1^6; sbit motc = P1^7; sbit motd = P3^5; unsigned int n=1,x=0; void delay(unsigned int t); void right(); void left(); void delay(unsigned int t) //延时函数 { unsigned int i,j; for(i=0;i<t;i++) for(j=0;j<114;j++); } void right() //反转函数 { while(x++!=500) { mota=0; motb=1; motc=1; motd=1; delay(n); mota=0; motb=0; motc=1; motd=1; delay(n); mota=1; motb=0; motc=1; motd=1; delay(n); mota=1; motb=0; motc=0; motd=1; delay(n); mota=1; motb=1; motc=0; motd=1; delay(n); mota=1; motb=1; motc=0; motd=0; delay(n); mota=1; motb=1; motc=1; motd=0; delay(n); mota=0; motb=1; motc=1; motd=0; delay(n); } } void left() //正转函数 { while(x++!=500) { motd=0; motc=1; motb=1; mota=1; delay(n); motd=0; motc=0; motb=1; mota=1; delay(n); motd=1; motc=0; motb=1; mota=1; delay(n); motd=1; motc=0; motb=0; mota=1; delay(n); motd=1; motc=1; motb=0; mota=1; delay(n); motd=1; motc=1; motb=0; mota=0; delay(n); motd=1; motc=1; motb=1; mota=0; delay(n); motd=0; motc=1; motb=1; mota=0; delay(n); } } void main() { while(1) { x=0; left(); delay(10); x=0; right(); delay(10); } }
牛刀小试7.3数码管最低位显示'E'
做的时候参考了教程、然后把0-f都给定义了。
代码如下、请指教哈哈
#include<stc89.h> code unsigned char segment[] = {0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x08,0x03,0x46,0x21,0x06,0x0e}; //0到f花样,其中a为10、b为11、类推 code unsigned char select[] = {0xff,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; unsigned char p=0; sbit hc595st=P0^4; sbit hc595out=P2^3; sbit hc595dat=P0^2; void hc595write(unsigned char dat); void led(unsigned int x,unsigned char n,unsigned char dp); void delay(unsigned int time); void error(); void error() //错误显示函数 { led(14,5,0); led(10,4,0); led(10,3,0); led(0,2,0); led(10,1,0); } void delay(unsigned int time) //延时函数 { unsigned int i,j; for(i=0;i<time;i++) for(j=0;j<2;j++); } void hc595write(unsigned char dat) // 写入数据 { unsigned char m; hc595out=0; for(m=0;m<8;m++) { hc595st=0; if(0x80&dat) hc595dat=1; else hc595dat=0; hc595st=1; delay(3); dat<<=1; } } void led(unsigned int x,unsigned char n,unsigned char dp) //显示(数码,位数,是否小数点) { if((x<16)&&(x>=0)&&(n<9)&&(n>=0)) //判断出错 { if(dp!=0) dp=segment[x]; else dp=segment[x]|0x80; hc595write(dp); hc595write(select[n]); hc595out=1; delay(1); hc595out=0; delay(1); } else p=1; } void main() { while(1) { if(p) error(); else led(14,1,0); //最低位显示”E“ } }
牛刀小试13.3:在 LCD1602 的第一行显示“Hello!”,第二行显示“The world!”
调试了一晚、参考了一些资料、然后自己改改、弄了个头文件、以后要用到1602就比较方便了,共享给大家哈哈,不足指出、麻烦指出!多谢!
以下是主程序:
#include<stc89.h> #include<1602.h> void main(void) { code uchar *dat="Hello!"; code uchar *dats="The World!"; lcdinit(); DisplayListChar(0,0,dat); DisplayListChar(0,1,dats); while(1); }
头文件要不要来个回复可见呢
——回复可见内容——
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |