色婷婷AⅤ一区二区三区|亚洲精品第一国产综合亚AV|久久精品官方网视频|日本28视频香蕉

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > AVR128的程序——數(shù)碼管時(shí)鐘顯示

          AVR128的程序——數(shù)碼管時(shí)鐘顯示

          作者: 時(shí)間:2016-11-22 來(lái)源:網(wǎng)絡(luò) 收藏
          #include
          #include
          #define uchar unsigned char
          #define uintunsigned int
          void timer1_init(void);
          void display1(uchar FirstBit,uchar Num);
          void display2(uchar FirstBit,uchar Num);
          void display3(uchar FirstBit,uchar Num);
          void display4(uchar FirstBit,uchar Num);
          void Delayms(uint MS);
          uchar TempData1[8];
          uchar TempData2[8];
          uchar TempData3[8];
          uchar WeiMa[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
          uchar led_discode[11]={0xc0,0xf9,0xa4,0xb0,0x99,
          0x92,0x82,0xf8,0x80,0x90,0xff};
          uchar temp=0x01;
          uint num=0,fen=19,shi=20;
          void main(void)
          {
          uchar i,temp;
          DDRA=0XFF;
          PORTA=0XFF;
          DDRC=0XFF;
          PORTC=0XFF;
          DDRF|=0X0E;
          PORTF|=0X0E;
          PORTF&=0xF7;
          DDRB |=0X10;
          PORTB|=0X10;
          timer1_init();
          SEI();
          while(1)
          {
          TempData1[1] = led_discode[num];
          TempData1[0] = led_discode[num/10];
          TempData2[1] = led_discode[fen];
          TempData2[0] = led_discode[fen/10];
          TempData3[1] = led_discode[shi];
          TempData3[0] = led_discode[shi/10];
          display1(6,2);
          display2(3,2);
          display3(0,2);
          display4(2,1);
          display4(5,1);
          }
          }
          void timer1_init(void)
          {
          TCNT1H = 0xE1;
          TCNT1L = 0x7C;
          TCCR1A = 0x00;
          TCCR1B = 0x05;
          TIMSK = 0x04;
          }
          #pragma interrupt_handler timer1_ovf_isr:15
          void timer1_ovf_isr(void)
          {
          TCNT1H = 0xE1;
          TCNT1L = 0x7C;
          num++;
          if(num==60)
          {
          num=0;
          fen++;
          if(fen==60)
          {
          fen=0;
          shi++;
          if(shi==24)
          {
          shi=0;
          }
          }
          }
          }
          void display1(uchar FirstBit,uchar Num)
          {
          unsigned char i;
          for(i=0;i
          {
          PORTC=led_discode[10];
          PORTA=WeiMa[i+FirstBit];
          PORTC=TempData1[i];
          Delayms(2);
          }
          }
          void display2(uchar FirstBit,uchar Num)
          {
          unsigned char i;
          for(i=0;i
          {
          PORTC=led_discode[10];
          PORTA=WeiMa[i+FirstBit];
          PORTC=TempData2[i];
          Delayms(2);
          }
          }
          void display3(uchar FirstBit,uchar Num)
          {
          unsigned char i;
          for(i=0;i
          {
          PORTC=led_discode[10];
          PORTA=WeiMa[i+FirstBit];
          PORTC=TempData3[i];
          Delayms(2);
          }
          }
          void display4(uchar FirstBit,uchar Num)
          {
          unsigned char i;
          for(i=0;i
          {
          PORTC=led_discode[10];
          PORTA=WeiMa[i+FirstBit];
          PORTC=0XBF;
          Delayms(2);
          }
          }
          void Delayms(uint MS)
          {
          uint i,j;
          for( i=0;i
          for(j=0;j<1141;j++);
          }


          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉