Matrix hiển thị trái tim 3 màu di chuyển từ dưới lên trên





// PIC16F887 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON       // RE3/MCLR pin function select bit (RE3/MCLR pin function is MCLR)
#pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = OFF      // Brown Out Reset Selection bits (BOR disabled)
#pragma config IESO = OFF       // Internal External Switchover bit (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
#pragma config LVP = OFF        // Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming)

// CONFIG2
#pragma config BOR4V = BOR40V   // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
#pragma config WRT = OFF        // Flash Program Memory Self Write Enable bits (Write protection off)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.





#include <xc.h>
#define _XTAL_FREQ 4000000
const unsigned char chonhang[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};


const unsigned char maled_do[]={  
                         
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,
0x00,0x00,0x00,0x00,0x00,0x00,0x66,0xFF,
0x00,0x00,0x00,0x00,0x00,0x66,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x66,0xFF,0xFF,0xFF,
0x00,0x00,0x00,0x66,0xFF,0xFF,0xFF,0x7E,
0x00,0x00,0x00,0xFF,0xFF,0xFF,0x7E,0x3C,
0x00,0x00,0x00,0xFF,0xFF,0x7E,0x3C,0x18,
0x00,0x00,0x00,0xFF,0x7E,0x3C,0x18,0x00,
0x00,0x00,0x00,0x7E,0x3C,0x18,0x00,0x00,
0x00,0x00,0x00,0x3C,0x18,0x00,0x00,0x00,
0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x20,0x10,0x00,0x00,0x00,0x00,0x00,
0xC0,0x60,0x30,0x18,0x00,0x00,0x00,0x00,
0xC0,0xE0,0x70,0x38,0x18,0x00,0x00,0x00,
0xC0,0xE0,0xF0,0x78,0x3C,0x18,0x00,0x00,
0x40,0xE0,0xF0,0xF8,0x7C,0x3C,0x18,0x00,
0x00,0x60,0xF0,0xF8,0xFC,0x7E,0x3C,0x18,
0x00,0x00,0x60,0xF8,0xFC,0xFE,0x7E,0x3C,
0x00,0x00,0x00,0x60,0xFC,0xFE,0xFF,0x7E,
0x00,0x00,0x00,0x00,0x64,0xFE,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x66,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x66,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const unsigned char maled_xanh[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x66,0x00,0x00,0x00,
0x00,0x00,0x00,0x66,0xFF,0x00,0x00,0x00,
0x00,0x00,0x66,0xFF,0xFF,0x00,0x00,0x00,  
0x00,0x66,0xFF,0xFF,0xFF,0x00,0x00,0x00,
0x66,0xFF,0xFF,0xFF,0x7E,0x00,0x00,0x00,
0xFF,0xFF,0xFF,0x7E,0x3C,0x00,0x00,0x00,
0xFF,0xFF,0x7E,0x3C,0x18,0x00,0x00,0x00,
0xFF,0x7E,0x3C,0x18,0x00,0x00,0x00,0x00,
0x7E,0x3C,0x18,0x00,0x00,0x00,0x00,0x00,
0x3C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x3C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
0x7E,0x3C,0x18,0x00,0x00,0x00,0x00,0x00,
0xFF,0x7E,0x3C,0x18,0x00,0x00,0x00,0x00,
0xFF,0xFF,0x7E,0x3C,0x18,0x00,0x00,0x00,
0xFF,0xFF,0x7F,0x3E,0x1C,0x08,0x00,0x00,
0x66,0xFF,0x7F,0x3F,0x1E,0x0C,0x00,0x00,
0x00,0x66,0x7F,0x3F,0x1F,0x0E,0x04,0x00,
0x00,0x00,0x66,0x3F,0x1F,0x0F,0x06,0x00,
0x00,0x00,0x00,0x26,0x1F,0x0F,0x07,0x02,
0x00,0x00,0x00,0x00,0x06,0x0F,0x07,0x03,
0x00,0x00,0x00,0x00,0x00,0x06,0x07,0x03,
0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x03,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,


0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};









int i=0;
int j=0;
int dat=0;
void main(void)
{
    ANSEL=0x00;
    ANSELH=0x00;
    TRISB=0;
    TRISC=0;
    TRISD=0;
    dat=0;

    while(1)
    {

        if(dat>=240)
        {
            dat=0;
        }
        for(j=0;j<=50;j++)
        {
            for(i=0;i<=7;i++)
            {
                PORTB=chonhang[i];
                PORTC=maled_do[dat+i];
                PORTD=maled_xanh[dat+i];
                __delay_ms(10);
            //}
            }
        }
            dat=dat+8;
       
    }
}

Previous
Next Post »