Cstyle的嵌入式之:那些年我们一起写过的单片机程序,世上最简单的单片机程序

2019-04-15 14:53发布

    周末回家,正漫无目的的浏览着网站,突有一QQ消息弹出自称是大学学生因不熟悉单片机,老师催作业太急,需要求助,题目大概如下
正好闲着没事,就说我们也是那个时候过来的,就来随便写写,看下当初的东西是否都还给老师了,就打开了MDK开始敲起来,大概半小时终于完成了,小伙伴们来围观下,嘿嘿。虽然它的电路图漏洞百出,不过看起来应该是个示意图,所以我的程序也算是示意,逻辑大概通顺,没有编译调试过,也可能有语法错误不过这不影响我回忆单片机的心情。O(∩_∩)O   #include
static unsigned code char DecodeNum[16]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};//需要调试,取字模,解码
#typedef ONE 1  //select the first LED #typedef TWO 2  //select the second LED #typedef THR 3  //select the third  LED #typedef FOR 4  //select the four LED
#typedef Delay1MS 1 #typedef Delay100MS 100 #typedef Delay1S    100000

void Put8(unsigned char Data8,unsigned char Cs); void Puts8(unsigned char *Data8,Unsigned char Length); void Delay(unsigned int Time);
main() {      //添加输出的任务   //例子1:输出数字 5 到第三个LED上     //例子2:循环输出一串数字到四个LED上   unsigned char data8[7]={1,2,3,4,5,6,7};
  Put8(5,3); //ext.1
  while(1)    //ext.2 {   Puts8(data8,7);   Delay(Delay1S);  }
}

//output 8 bit date to port 0 void Out8(uniigned char Data8) { P0 = Data8; }
//select one LED to show the data output from port0 void Cs(Unsigned char Data8) { switch(Data8) { case ONE: { P2^1=0; break; } case TWO : { P2^2=0; break; } case THR : { P2^3=0; break; } case FOR : { P2^4=0; break; } default break; } }
//show one data on the selected LED void Put8(unsigned char Data8,unsigned char Cs) { Out8(DecodeNum[Data8]); Cs(Cs); }

//show a string on the for LED void Puts8(unsigned char *Data8,Unsigned char Length) { unsigned int i;
for(i=0;i{ i=i%FOR; Put8([*Data8++],i+1); Delay(Delay100MS); } }
//Delay for a while void Delay(unsigned int Time) { ungingned int i; for(i=0;i 先到这里。 转载请注明出处 Cstyle.z.zhou@gmail.com  //  http://blog.csdn.net/CStyle_0x007