#include #include "hardware.h" void init(void){ //stel de tris goed in voor de bpoort en SPI uitgangen //76543210 TRISA = 0b00000000; ANSELA = 0b00000000; TRISB = 0b00000000; ANSELB = 0b00000000; TRISC = 0b10000000; ANSELC = 0b00000000; //osc instellingen OSCCON = 0b01110000; OSCCON2 = 0b00000000; OSCTUNE = 0b01000000; //spi instellingen SSP2STAT = 0b00000000; SSP2CON1 = 0b00100001; //timer1 T1CON = 0b00000001; //interrupts INTCON = 0b11000000; INTCON2 = 0b10000000; INTCON3 = 0b00000000; PIR1 = 0; PIR2 = 0; PIE1 = 0b00101001; PIE2 = 0b00000000; RCON = 0b00000000; //uart //sync = 0, brgh = 1, brg16 = 1; 115200 baud //SPBRGH1 = 0x06; //SPBRG1 = 0x82; //138 SPBRGH1 = 0; SPBRG1 = 62; //138 TXSTA1 = 0b00100100; RCSTA1 = 0b10010000; BAUDCON1= 0b00001000; } void interrupt isr(void) { if(SSP2IF) { if(SPITeller < 24) { SSP2BUF = SPIBuffer[x + rijcnt][y++]; if(y > 5) y=0, x+=16; SPITeller++; } else { StrobePuls; EnableAan; SSP2IE = 0; x=0; y=0; } SSP2IF = 0; } if(TMR1IF) { EnableUit; rijcnt++; if(rijcnt >= 16){ rijcnt = 0; if(Tmr)Tmr--; } LATA = PORTA & 0b11111000; if(rijcnt <= 7) { LATA = (7 - rijcnt) | LATA; FirstRow = 1; SecondRow = 0; } else { LATA = 7 - rijcnt - 8 | LATA; FirstRow = 0; SecondRow = 1; } SPITeller = 0; SSP2IF = 1; SSP2IE = 1; TMR1IF = 0; TMR1H = 0xC0; } if(RC1IF){ char R = RCREG1; if(!Tmr) { recv = RC_RCV; rcX = 0; rcY = 0; } Tmr = 2; switch(recv){ case RC_RCV: SPIBuffer[rcX][rcY++] = R; if(rcY > 5) rcX++, rcY = 0; if(rcX > 63)recv = RC_NEXT; break; case RC_NEXT: TXREG1 = R; break; default: recv = RC_RCV; SPIBuffer[0][0] = 0xAA; break; } } }