Hiển thị các bài đăng có nhãn lập trình. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn lập trình. Hiển thị tất cả bài đăng

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;
       
    }
}

LED Matrix hiển thị trái tim dịch 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 choncot[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
const unsigned char maled[]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
                        0xFF,0x7F,0x7F,0xFF,0xFF,0x7F,0x7F,0xFF,
                        0x7F,0x3F,0x3F,0x7F,0x7F,0x3F,0x3F,0x7F,
                        0x3F,0x1F,0x1F,0x3F,0x3F,0x1F,0x1F,0x3F,
                        0x1F,0x0F,0x0F,0x1F,0x1F,0x0F,0x0F,0x1F,
                        0x8F,0x07,0x07,0x0F,0x0F,0x07,0x07,0x8F,
                        0xC7,0x83,0x03,0x07,0x07,0x03,0x83,0xC7,
                        0xE3,0xC1,0x81,0x03,0x3,0x81,0xC1,0xE3,
                        0xF1,0xE0,0xC0,0x81,0x81,0xC0,0xE0,0xF1,
                        0xF8,0xF0,0xE0,0xC0,0xC0,0xE0,0xF0,0xF8,
                        0xFC,0xF8,0xF0,0xE0,0xE0,0xF0,0xF8,0xFC,
                        0xFE,0xFC,0xF8,0xF0,0xF0,0xF8,0xFC,0xFE,
                        0xFF,0xFE,0xFC,0xF8,0xF8,0xFC,0xFE,0xFF,
                        0xFF,0xFF,0xFE,0xFC,0xFC,0xFE,0xFF,0xFF,
                        0xFF,0xFF,0xFF,0xFE,0xFE,0xFF,0xFF,0xFF,
                        0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
                        0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
                        0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
                        0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
                        0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
};
const unsigned char maled1[]={
    0xFF,0x7F,0x7F,0xFF,0xFF,0x7F,0x7F,0xFF,
    0xFF,0x7F,0x7F,0xFF,0xFF,0x7F,0x7F,0xFF,
    0xFF,0x7F,0x7F,0xFF,0xFF,0x7F,0x7F,0xFF,
    0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
    0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
    0xFF,0x7F,0x7F,0xFF,0xFF,0x7F,0x7F,0xFF,
    0xFF,0x7F,0x7F,0xFF,0xFF,0x7F,0x7F,0xFF,
    0xFF,0x7F,0x7F,0xFF,0xFF,0x7F,0x7F,0xFF,
};
int i=0;
int j=0;
int dat=0;
void delay(void)
{
    __delay_ms(5);
}
void main(void)
{
    ANSEL=0x00;
    ANSELH=0x00;
    TRISB=0;
    TRISC=0;
//    TRISD=0;
    dat=0;
    while(1)
    {

        if(dat>=136)
        {
            dat=0;
        }
        for(j=0;j<=10;j++)
        {
            for(i=0;i<=7;i++)
            {
                PORTC=choncot[i];
//                PORTD=choncot[i];
                PORTB=maled[dat+i];
//                PORTB=maled1[dat+i];
                RB3=RB4=0;
                TRISD=0;
                PORTD=choncot[i];
                delay();                    
            }
            //}
           
        }
            dat=dat+8;
       
    }
}
       

Hiển thị Điện áp với ADC module



#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "lcd.h"
#define _XTAL_FREQ 4000000
// 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.
unsigned int read_adc(){
    __delay_us(6);
    GO_nDONE=1;
    while(GO_nDONE==1);
    return (((unsigned int)ADRESH)<<8) |ADRESL;
}
void adc_init(){
    TRISA3=1;
    ANS3=1;
    ADCS1=0;ADCS0=1;
    VCFG1=0;VCFG0=0;
    CHS3=0;CHS2=0;CHS1=1;CHS0=1;//kenh AN3
    ADFM=1;//CANH TRAI
    ADON=1;//KICH HOAT ADC
    ADIF=0;
    GIE=PEIE=ADIE=0;
}
unsigned int mid_filter_adc(){
    unsigned char i,level_filter=100;
    unsigned long sum=0;
    for(i=1;i<=level_filter;i++)
    {
        sum=sum+read_adc();
    }
    return (sum/level_filter);
}

void main(void) {
   
    unsigned long adc_val;
    float voltage=0;
    ANSEL=0x08;
    ANSELH=0x00;
    TRISA3=1;
    lcd_init();
    adc_init();
    lcd_gotoxy(10,1);
    printf("(mV)");
    lcd_gotoxy(1,0);
    printf("Dig. Voltmeter");
    while(1)
    {
        adc_val=mid_filter_adc();//loc nhieu trung binh
        voltage=(adc_val*5.0f/1023);
//        milivolt=voltage*1000;
        lcd_gotoxy(4,1);
        printf("%3.2f",voltage*1000);
       
    }
}