// LCD driver - 4-bitova komunikace // USART // PIC16F648A #include #define _XTAL_FREQ 4000000 // Fuse bity __CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & BOREN_OFF & LVP_OFF & CPD_OFF & CP_OFF); // Inicializace void init() { // INTCON GIE = 1; // Global Interrupt Enable // TRISB TRISB1 = 1; // USART RX TRISB2 = 1; // USART TX } // USART Master TX inicializace (RB1, RB2) void usartMasterTXInit() { SYNC = 1; // Synchronous mode BRGH = 0; // Low speed SPBRG = 103; // 9600 KBAUD CSRC = 1; // Master mode SPEN = 1; // Serial port enabled (RB1/RX/DT and RB2/TX/CK) TXIE = 1; // USART transmit interrupt TXEN = 1; // Transmit enabled } // obsluha preruseni void interrupt gi() { GIE = 0; if (TXIF) { lcdPrintString(2,1,"Data sent ..."); TXIF = 0; } GIE = 1; } // Hlavni program void main() { init(); usartMasterTXInit(); __delay_ms(10000); lcdPrintString(1,1,"USART Master"); lcdPrintString(2,1,"Sending data ..."); __delay_ms(1000); TXREG = 0b11111111; while (1) { } }