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

📄 动态灯.c

📁 简单的小程序
💻 C
字号:


#include "msp430x11x1.h"
#define P6DIR_              (0x036)  
DEFC(   P6DIR             , P6DIR_)

#define P6OUT_              (0x035)  /* Port 6Output defination,beacause
                                         it not defined in the head file
                                          we define it here*/
DEFC(   P6OUT             , P6OUT_)

#define uchar unsigned char

void display_1(uchar num);
void display_2(uchar num);
void init(void);
void disp(uchar led_1,uchar led_2,uchar led_3,uchar led_4); 

char code[10]={0xed,0xc0,0x8f,0xce,0xe2,0x6e,0x6f,0xc8,0xef,0xee};//the code of each num
volatile uchar bit_1,bit_2,bit_3,bit_4;  //the order of leds
  char led_one,led_two,led_three,led_four;
uchar counter_1=0,counter_2=0,counter_3=0,counter_4=0;
unsigned int i,j; 
void main(void)
{
 
 
 
 P1DIR |=0x0f;
 P6DIR |=0xff;
 P6OUT=0x0;
 led_one=P1OUT&0x01;    //p1.0
 led_two=P1OUT&0x02;    //p1.1
 led_three=P1OUT&0x04;  //p1.2
 led_four=P1OUT&0x08;   //p1.3 we define the led here
 init();
 //   disp(counter_1,counter_2,counter_3,counter_4);
/*
while(1) 
{
  init(); 
   disp(counter_1,counter_2,counter_3,counter_4);
} */
 

 
while(1)
  {
    
    /*
    for(i=0;i<10000;i++)
    counter_1++;
    if(counter_1==9){counter_1=0;counter_2++;}
    if(counter_2==9){counter_2=0;counter_3++;}
    if(counter_3==9){counter_3=0;counter_4++;}
    if(counter_4==9){counter_4=0;}
    */
      disp(1,2,8,7);
 


}
}
void init(void)
{
  bit_1=1;
  bit_2=0;
  bit_3=0;
  bit_4=0;

  //P6OUT=0xff;
}

void disp_1(uchar num)
{
 // P1OUT=0xff;
   //for(i=0;i<200;i++);
 P6OUT=code[num];
  P1OUT=0x0e;
 // led_one=0;          //we set it to ground to light the led
 
 P1OUT=0x0f;
 
 /*  
    for(i=0;i<100;i++)
  {
    for(j=0;j<100;j++);}
*/
}

void disp_2(uchar num)
{
  //P1OUT=0xff;
 // for(i=0;i<200;i++);
 P6OUT=code[num];
  P1OUT=0x0d;
 P1OUT=0x0f;
   
 //  led_two=0;
  
  /*
    for(i=0;i<100;i++)
  {
    for(j=0;j<100;j++);}
*/
}

void disp_3(uchar num)
{
  //P1OUT=0xff;
   //for(i=0;i<200;i++);
    P6OUT=code[num];
  P1OUT=0x0b;
  P1OUT=0x0f;
 
  // led_three=0;

 /* 
    for(i=0;i<100;i++)
  {
    for(j=0;j<100;j++);}
*/
}
void disp_4(uchar num)
{
  //P1OUT=0xff;
  //for(i=0;i<200;i++);
   P6OUT=code[num];
  P1OUT=0x07;
 // led_four=0;
 P1OUT=0x0f;
 
 /*
    for(i=0;i<100;i++)
  {
    for(j=0;j<100;j++);}
*/
}

void disp(uchar led_1,uchar led_2,uchar led_3,uchar led_4)
{
  P1DIR=0xff;
  disp_1(led_1);
  disp_2(led_2);
  disp_3(led_3);
  disp_4(led_4);
//  P6OUT=code[led_1]+code[led_2]+code[led_3]+code[led_4];

}

⌨️ 快捷键说明

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