⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 s12DG128芯片上
💻 C
字号:
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"

void delay(void){
  unsigned int i,j;
  for(i=0;i<10;i++){
    for(j=0;j<10;) j++;
  }
}

int convert(unsigned int i){
  switch(i){
    case 0:return 0x48;
    case 1:return 0xfc;
    case 2:return 0x0e;
    case 3:return 0x8c;
    case 4:return 0xb8;
    case 5:return 0x89;
    case 6:return 0x09;
    case 7:return 0xec;
    case 8:return 0x08;
    case 9:return 0x88;
    default:return 0xff;
  }
}

void Digit_select(unsigned int i,unsigned int j,unsigned int k){
  
    PTH_PTH7=(i+1)%2;
    PTH_PTH6=(j+1)%2;
    PTH_PTH5=(k+1)%2;
    }
  



void main(void) {
  int a=0,b=0;
  DDRB = 0xff;
  DDRT_DDRT6 = 0b1;
  DDRT_DDRT5 =0b1;
  DDRH_DDRH7=0b1;
  DDRH_DDRH6=0b1;
  DDRH_DDRH5=0b1;
  Digit_select(0,0,0);
  PORTB = 0x00;
  
  
  EnableInterrupts;

  for(;;) {
  PTT_PTT5=0b0;
  PTT_PTT6=0b1;
  PORTB =convert(a/100000);
  Digit_select(1,0,0);
  delay();
  Digit_select(0,0,0);
  PORTB = convert((a%100000)/10000);
  Digit_select(0,1,0);
  delay();
  Digit_select(0,0,0);
  PORTB = convert((a%10000)/1000);
  Digit_select(0,0,1);
  delay();
  Digit_select(0,0,0);
  PTT_PTT6=0b0;
  PTT_PTT5=0b1;
  PORTB =convert((a%1000)/100);
  Digit_select(1,0,0);
  delay();
  Digit_select(0,0,0);
  PORTB = convert((a%100)/10);
  Digit_select(0,1,0);
  delay();
  Digit_select(0,0,0);
  PORTB = convert(a%10);
  Digit_select(0,0,1);
  delay();
  Digit_select(0,0,0);
  b++;
  if(b==100){
    b=0;
    if(a==999999)a=0;
    else a++;
  }
  
                    
      } /* wait forever */
  /* please make sure that you never leave this function */
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -