Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <xc.h>
- #include "16x2LCDHD44780.h"
- #include "msspi2c.h"
- __CONFIG(LVP_OFF & FCMEN_OFF & IESO_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
- /*
- Processor Type: PIC16F887
- Configuration Word 1
- Debug Disabled (default - controlled by PICkit 2)
- Low Voltage Programming Disabled (LVP)
- Fail Safe Clock Monitor Disabled (FCMEN)
- Internal External Oscillator Switchover Disabled (IESO)
- Brown Out Reset Disabled (BOR)
- Program Code External Read Protect Disabled (default)
- Data EEPROM External Read Protect Disabled (default)
- RE3 has MCLR function (default)
- Power Up Timer On (PWRTE)
- Watchdog Timer Off (WDTE)
- High Speed Oscillator Mode Enabled (FOSC_HS)
- Configuration Word 2
- Brown Out Reset Voltage 4V (default)
- Program Memory Write Protect Disabled (default)
- */
- #define _XTAL_FREQ 16000000
- #define _I2C_BAUD 400000
- #define _UART_BAUD 31250
- #define _I2C_BRG ((_XTAL_FREQ / _I2C_BAUD) / 4) - 1
- #define _UART_BRG ((_XTAL_FREQ / _UART_BAUD) / 16) - 1
- void main(void)
- {
- PORTA = 0x00; //clear PORTA latch
- PORTB = 0x00; //clear PORTB latch
- PORTC = 0x00; //clear PORTC latch
- PORTD = 0x00; //clear PORTD latch
- PORTE = 0x00; //clear PORTE latch
- ANSEL = 0x00; //all port pins digital I/O
- ANSELH = 0x00;
- TRISA = 0x00; //RA0-RA5 output
- TRISB = 0x00; //RB0-RB7 output
- TRISC = 0b11011001;
- /*
- RC0 - Write Enable (I2C EEPROM)
- RC1 - Output
- RC2 - Output
- RC3 - SCL
- RC4 - SDA
- RC5 - Output
- RC6 - UART TxD
- RC7 - UART RxD
- */
- TRISD = 0x00; //RD0-RD7 output
- TRISE = 0x00; //RE0-RE2 output
- //I2C Initialization
- SSPADD = _I2C_BRG; //init baud rate for I2C
- SMP = 0x00; //enable slew rate control for 400kHz operation
- SSPCON2 = 0xFF; //everything idle
- SSPCON = 0b00101000; //I2C Master Mode, Baud = Fosc / 4*(SSPADD+1)
- //UART Initialization
- BAUDCTL = 0x00; //non-inverted data on TxD/RxD, disable baud rate detection
- SPBRG = _UART_BRG; //init baud rate for serial port
- SPBRGH = 0x00;
- TXSTA = 0b00100100; //enable tx, high speed brg
- RCSTA = 0b10010000; //enable rx, enable serial port
- i2cStartBit();
- while(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement