Chuong trinh quet led 7 seg cua anh kiên
Code:
// chương trinh quet led cua anh kiên // Khai bao cac file header #include <AT89X52.H> #include <Kit8051.h> // Khai bao cac bien toan cuc unsigned char code LED_code[] = {Number0, Number1, Number2, Number3, Number4, Number5, Number6, Number7, Number8, Number9}; // Khai bao cac ham void Delay(unsigned int n); void InitSystem(void); void Display(unsigned char digit1, unsigned char digit2, unsigned char digit3, unsigned char digit4); // Dinh nghia cac ham void Delay(unsigned int n) { unsigned int i,j; for(i=0;i<n;i++) for(j=0;j<100;j++); } void Display(unsigned char digit1, unsigned char digit2, unsigned char digit3, unsigned char digit4) { // Hien thi so thu nhat LED = LED_code[digit1]; K1 = 0; Delay(1); K1 = 1; // Hien thi so thu hai LED = LED_code[digit2]; K2 = 0; Delay(1); K2 = 1; // Hien thi so thu ba LED = LED_code[digit3]; K3 = 0; Delay(1); K3 = 1; // Hien thi so thu tu LED = LED_code[digit4]; K4 = 0; Delay(1); K4 = 1; } void InitSystem(void) { LCD_E = 0; } // Chuong trinh chinh void main(void) { // Khoi tao he thong InitSystem(); // Vong lap vo tan while(1) { Delay(10); Display(1,2,3,4); } }
Comment