Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <p18f4520.h>
- #include <timers.h>
- #include <usart.h>
- #include <delays.h>
- int counter = 0;
- char tmp;
- char maska = 0xF0;
- #define BUTTON_PORT PINC
- #define BUTTON_LINE 0
- void timer_isr (void);
- #pragma code high_vector = 0x08
- #pragma config LVP = OFF, DEBUG = OFF
- void high_interrupt (void)
- {
- _asm GOTO timer_isr _endasm
- }
- #pragma code
- #pragma interrupt timer_isr
- void timer_isr (void)
- {
- counter++;
- if (counter == 255)
- {
- counter = 0;
- }
- INTCONbits.TMR0IF = 0;
- }
- void delay()
- {
- int i, j;
- for(i=0; i<=400; i++)
- {
- }
- }
- //char liczby[16] = { 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E, 0xC0 };
- char liczby[16] = { 0xB0, 0xF8, 0x83, 0x8E, 0xA4, 0x82, 0x88, 0x86, 0xF9, 0x92, 0x90, 0xA1, 0xC0, 0x99, 0x80, 0xC6};
- char data[4] = { 0xB0, 0xF9, 0xC0, 0xA4 };
- void CheckKeyboards(char* data, int position)
- {
- if((PORTB & 0x08) == 0x00)
- {
- data[3] = data[2];
- data[2] = data[1];
- data[1] = data[0];
- data[0] = liczby[position * 4];
- }
- if((PORTB & 0x04) == 0x00)
- {
- data[3] = data[2];
- data[2] = data[1];
- data[1] = data[0];
- data[0] = liczby[position * 4 + 1];
- }
- if((PORTB & 0x02) == 0x00)
- {
- data[3] = data[2];
- data[2] = data[1];
- data[1] = data[0];
- data[0] = liczby[position * 4 + 2];
- }
- if((PORTB & 0x01) == 0x00)
- {
- data[3] = data[2];
- data[2] = data[1];
- data[1] = data[0];
- data[0] = liczby[position * 4 + 3];
- }
- //Delay10KTCYx(1);
- }
- void Print(char* data)
- {
- LATB = 0xEF;
- LATD = data[0];
- //Delay10KTCYx(1);
- delay();
- LATB = 0xDF;
- LATD = data[1];
- //Delay10KTCYx(1);
- delay();
- LATB = 0xBF;
- LATD = data[2];
- //Delay10KTCYx(1);
- delay();
- LATB = 0x7F;
- LATD = data[3];
- //Delay10KTCYx(1);
- delay();
- }
- void main(void)
- {
- int i=0;
- TRISB = 0x0F;
- TRISD = 0x00;
- INTCON2bits.RBPU = 0x0;
- ADCON1bits.PCFG0 = 0x1;
- ADCON1bits.PCFG1 = 0x1;
- ADCON1bits.PCFG2 = 0x1;
- ADCON1bits.PCFG2 = 0x1;
- //INTCONbits.GIE = 1;
- while (1)
- {
- LATB = 0xEF;
- CheckKeyboards(data, 0);
- LATB = 0xDF;
- CheckKeyboards(data, 1);
- LATB = 0xBF;
- CheckKeyboards(data, 2);
- LATB = 0x7F;
- CheckKeyboards(data, 3);
- for(i=0; i<4; i++)
- {
- Print(data);
- }
- //Delay10KTCYx(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement