* Created on October 19, 2014, 3:14 PM
*
* LCD Ports:
* D4 RB0
* D5 RB1
* D6 RB2
* D7 RB3
* RS RB4
* RW RB5
* EN RB6
*
*/
#include <xc.h>
// CONFIG1
#pragma config FOSC = INTRC_NOCLKOUT, WDTE = OFF, PWRTE = OFF, MCLRE = OFF
#pragma config CP = OFF, CPD = OFF, BOREN = OFF, IESO = OFF, FCMEN = OFF
#pragma config LVP = OFF, DEBUG = OFF
// CONFIG2
#pragma config BOR4V = BOR40V, WRT = OFF
// Set Clock Freq. & Delays
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 20000000
#define __delay_us(x) _delay((unsigned long)((x)*(_XTAL_FREQ/20000000.0)))
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/20000.0)))
#endif
void main(void);
void SPIInit(void);
#include "lcd_hd44780_pic16.h"
// SPI Ports
#define SCK RC3
#define SDI RC4
#define SDO RC5
#define FALSE 0
#define TRUE 1
void Pic_Init(){
ANSELH = 0; // putting LCD on PORTB
TRISB = 0;
}
void SPIInit(void) {
INTCON = 0; // Disable all interrupts
TRISC3 = 1; // SCK=RC3 is the serial clock
TRISC4 = 1; // SDI=RC4 is serial data input
TRISC5 = 0; // SDO=RC5 is serial data output
SSPIF = 0;
SMP = 0; // Input data sampled at middle data output time
CKP = 1; // Idle state for clock is a high level
CKE = 0; // Transmit occurs on idle to active clock state
SSPEN = 1; // Enables serial port
SSPM3 = 0;
SSPM2 = 1;
SSPM1 = 0;
SSPM0 = 1;
}
void main(){
unsigned char expVal = 0;
int errCount = 0;
unsigned char dummy;
Pic_Init();
SPIInit();
LCDInit(LS_NONE); //Initialize the LCD Module
LCDClear(); //Clear the display
//Write a string [LCDWriteStringXY(col, row, string)]
LCDWriteStringXY(0,0,"MegaTroniX");
__delay_ms(100);
LCDClear();
while(1)
{
while(BF==FALSE){} // Wait for SSPBUF Reception complete
dummy = SSPBUF; // Get data byte
LCDWriteIntXY(0, 0, dummy, -1);
LCDWriteIntXY(0, 1, expVal, -1);
if(dummy != expVal){
errCount++;
LCDWriteIntXY(8, 1, errCount, -1);
}
expVal++;
if(expVal == 50){
LCDClear();
expVal = 0;
}
}
}