Settings | Sign in | Sign up

There are currently 2 posts.

【程序】8位數碼管顯示

Floor 1 巨大八爪鱼 7/22/12 13:03
#include <iom16v.h>
#include <macros.h>
unsigned char const NUM[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void delay_ms(unsigned int k)
{
   unsigned int i,j;
  for (i=0;i<k;i++)
    for (j=0;j<1140;j++);
}
unsigned long power(unsigned char times)
{
    unsigned long num=10;
 unsigned char i;
 if (times==0)
    return 1;
 else
 {
    for (i=1;i<times;i++)
        num*=10;
    return num;
    }
}
void main()
{
    unsigned char i;
    unsigned long num=0; //數碼管上顯示的數字
    DDRA=0xff;
    PORTA=0xff;
 DDRC=0xff;
    PORTC=0xff;
 while (1)
 {
     for (i=0;i<8;i++) //i+1為從右數的位數
     {
         PORTC=~BIT(7-i);
      PORTA=NUM[num%power(i+1)/power(i)];
      delay_ms(1);
      PORTC=0xff;
      PORTA=0xff;
     }
  num++;
  if (num>99999999)
    num=0;
 }
}
Floor 2 巨大八爪鱼 7/22/12 20:48

從這個程序可以看出,單片機執行程序非常快的。

Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
©2010-2025 Purasbar Ver3.0 [Mobile] [Desktop]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported license.