LCD character serial interface C source code.
/*****************************************************/
/*
Serial_LCD_Test.c
Program for writing to Newhaven Display Serial LCDs
(c) Newhaven Display International, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/*****************************************************/
#include "e:\2321_tester\tester_init.h"
/********************************************************************
* *
* MAIN PROGRAM *
* *
********************************************************************/
void main(void)
{
OSCCON |= 0x73; // internal RC, 8MHz
PORTA = 0x00;
TRISA = 0xFF; // B'1111 1111'
PORTB = 0x00;
TRISB = 0xFF; // B'1111 1111'
PORTC = 0x75; // B'0111 0101'
TRISC = 0x00; // B'0000 0000'
GIE = 0;
INTCON = 0x00; // disable all interrupt
INTCON2 = 0x00; // enable port B pull-up
INTCON3 = 0x00;
/********************************************************************
set up adc for analog inputs
ADC clock = Fosc/8 (1 uSecond), adc off,
AN0 is contrast input, AN1 is backlight brightness input
********************************************************************/
ADCON0 = 0x00;
ADCON1 = 0x0D; // RA0, RA1 are analog inputs
ADCON2 = 0x15; // left just, 4TAD, Fosc/16, 0001 0101
/********************************************************************
set up timer 0 for 10 millisecond interrupt
timer 0 is a general purpose timer
********************************************************************/
T0CON = 0x46; // timer 0 control register
T1CON = 0xB0; // timer 1 off
spi_ss = 1;
if (!i2c_sel) {
com_mode = 3; // I2C
init_i2c();
}
else {
if (!spi_sel) {
com_mode = 2; // SPI
init_spi();
}
else {
com_mode = 1; // RS232
init_rs232();
}
}
/* END OF SPECIAL REGISTER INITIALIZATION */
tick_100m = 9; // 100 millisceond counter
tick_1s = 9; // 1 second counter
TMR0L = 100; // initialize to 100 counts
TMR0ON = 1;
TMR0IF = 0;
TMR0IE = 1;
contrast = 0;
contrast_f = 0;
bright = 0;
bright_f = 0;
serial_busy = 0;
TXREG = 0;
PEIE = 1;
GIE = 1; // enable global interrupt
delay_ms(100); // waiting for LCD to initialize
lcd_clear();
// Set Contrast
tx_packet[0] = 0xFE;
tx_packet[1] = 0x52;
tx_packet[2] = 40; // contrast 1 - 50
send_packet(3);
// Set Backlight Level
tx_packet[1] = 0x53;
tx_packet[2] = 15; // backlight 1 - 15
send_packet(3);
tx_packet[1] = 0x48; // underline cursor off
send_packet(2);
delay_ms(1000);
//*********************************************************
for (i = 0; i < 16; i++) { // "NewHaven Display"
tx_packet[i] = text6[i];
}
send_packet(16);
lcd_cursor(0x40);
delay_ms(100);
for (i = 0; i < 16; i++) { //"Serial LCD Demo"
tx_packet[i] = text7[i];
}
send_packet(16);
temp = 0;
for (;;) {
// Contrast Control
if (contrast_f && !serial_busy ) {
tx_packet[0] = 0xFE;
tx_packet[1] = 0x52;
tx_packet[2] = contrast_save;
send_packet(3);
contrast_f = 0;
}
// Backlight Brightness
if (bright_f && !serial_busy) {
tx_packet[0] = 0xFE;
tx_packet[1] = 0x53;
tx_packet[2] = bright_save;
send_packet(3);
bright_f = 0;
}
}
} /* end main */
/********************************************************************
send 'x' byte of the tx_packet[] to the serial port
********************************************************************/
void send_packet(unsigned int x)
{
unsigned int ix;
led = 1;
serial_busy = 1; // set busy flag
switch (com_mode) {
case 1: // RS232 mode
for (ix = 0; ix < x; ix++) {
while (!TXIF);
TXREG = tx_packet[ix];
}
while (!TRMT);
break;
case 2: // SPI
spi_ss = 0;
delay_cycles(5);
for (ix = 0; ix < x; ix++) {
SSPBUF = tx_packet[ix];
while(!BF);
temp = SSPBUF;
delay_us(5); // reduce effective clock rate
}
delay_cycles(5);
spi_ss = 1;
break;
case 3: // I2C
i2c_busy(0x50); // send address
for (ix = 0; ix < x; ix++) {
SSPBUF = tx_packet[ix];
wait_sspif();
}
PEN = 1; // send stop bit
while (PEN == 1); // wait until stop bit finished
break;
default:
break;
}
led = 0;
serial_busy = 0; // clear busy flag
}
/********************************************************************
wait for SSPIF set routine, add a software counter to ensure the
routine does not hang.
********************************************************************/
void wait_sspif(void)
{
loop_hi = 9;
loop_lo = 0xC4;
SSPIF = 0;
while (!SSPIF && loop_hi) {
loop_lo--;
if(!loop_lo)
loop_hi--;
}
SSPIF = 0;
}
/********************************************************************
i2c_busy routine poll the ACK status bit to see if device is busy
********************************************************************/
void i2c_busy(unsigned char x)
{
SEN = 1; // start bit
while(SEN); // wait until start bit finished
while (1) {
SSPIF = 0;
SSPBUF = x; // send write command
wait_sspif(); // wait until command finished
if (ACKSTAT) { // check ACK, if 1, ACK not received
RSEN = 1; // then sent start bit again
while (RSEN); // wait until start bit finished
}
else
break;
}
}
/********************************************************************
set lcd cursor
********************************************************************/
void lcd_cursor(unsigned int x)
{
tx_packet[0] = 0xFE;
tx_packet[1] = 0x45;
tx_packet[2] = x;
send_packet(3);
delay_ms(10);
}
/********************************************************************
clear one line of display
********************************************************************/
void clear_line(unsigned int x)
{
unsigned int ij;
for (ij = 0; ij < x; ij++) {
tx_packet[ij] = 0x20;
}
send_packet(x);
}
/********************************************************************
lcd clear
********************************************************************/
void lcd_clear(void)
{
tx_packet[0] = 0xFE;
tx_packet[1] = 0x51;
send_packet(2);
delay_ms(10);
}
/********************************************************************
initialize for USART interface
********************************************************************/
void init_rs232(void)
{
TXSTA = 0x26; // rs232 transmit status register
RCSTA = 0x80; // serial port enable
BAUDCTL = 0x08; // BRG16 = 1;
SPBRG = 207;
SPBRGH = 0;
}
/********************************************************************
initialize for spi interface
********************************************************************/
void init_spi(void)
{
TRISC |= 0x10;
SSPCON1 = 0x32; // master, 125K CLK, CKP = 1
temp = SSPBUF;
SSPOV = 0;
SSPIF = 0;
}
/********************************************************************
initialize for i2c interface
********************************************************************/
void init_i2c(void)
{
TRISC |= 0x18; // RC3, RC4 as inputs
SSPSTAT = 0x00;
SSPADD = 19; // 100K Hz
SSPCON1 = 0x28; // i2c master, enable SSP
temp = SSPBUF;
SSPOV = 0;
SSPIF = 0;
SSPIE = 0; // enable I2C interrupts
}
/********************************************************************
ADC read routine, read the selected adc channel and put the result
in adc_result.
********************************************************************/
void adc(unsigned char n)
{
switch (n) {
case 0: // adc channel 0, contrast
ADCON0 = 0x03;
break;
case 1: // adc channel 1, backlight
ADCON0 = 0x07;
break;
default:
break;
}
while (GODONE); // wait for end of convert
adc_result = ADRESH;
if (adc_result > 250)
adc_result = 250;
}
/*****************************************************************************/
/* interrupt routines */
/* timer 0 is set to interrupt at 100 Hz rate. */
/*****************************************************************************/
#int_timer0
void timer0_isr(void) /*interrupt handler routine*/
{
restart_wdt(); // reset watchdog timer
TMR0L = 100;
/********************************************************************
10 millisecond functions
********************************************************************/
if (tick_wait10)
tick_wait10--;
if (tick_100m) {
tick_100m--;
}
/********************************************************************
100 millisecond functions
********************************************************************/
else { // 100 millisecond function
tick_100m = 9; // reload 100 millisecond timer
if (tick_wait100) // general purpose 100 mSecond timer
tick_wait100--;
adc(0); // read contrast setting
contrast = adc_result / 5;
if (!contrast)
contrast = 1;
if (contrast != contrast_save) {
contrast_save = contrast;
contrast_f = 1;
}
adc(1); // read backlight setting
bright = adc_result / 15;
if (!bright)
bright = 1;
if (bright != bright_save) {
bright_save = bright;
bright_f = 1;
}
if (tick_1s) {
tick_1s--;
}
/********************************************************************
1 second functions
********************************************************************/
else {
tick_1s = 9; // reload 1 second timer
}
}
} /* end of timer 0 interrupt routine */
tester_init.h
/*****************************************************************************
* Copyright (c) 2018, Newhaven Display International
*
* This code is provided as an example only and is not guaranteed by Newhaven Display.
* Newhaven Display accepts no responsibility for any issues resulting from its use.
* The developer of the final application incorporating any parts of this
* sample code is responsible for ensuring its safe and correct operation
* and for any consequences resulting from its use.
*****************************************************************************/
// * August 15th, 2007
// * Definitions for serial LCD tester program
// * CCS Compiler
// *
// * Last Update : August 20th, 2007
/********************************************************************
function protocol:
0xFE, 0x41 - display on
0xFE, 0x42 - display off
0xFE, 0x45 - set cursor position
0xFE, 0x46 - home cursor
0xFE, 0x47 - underline cursor on
0xFE, 0x48 - underline cursor off
0xFE, 0x49 - move cursor left 1 space
0xFE, 0x4A - move cursor right 1 space
0xFE, 0x4B - blinking cursor on
0xFE, 0x4C - blinking cursor off
0xFE, 0x4E - back space.
0xFE, 0x51 - clear screen
0xFE, 0x52 - set contrast (1-50)
0xFE, 0x53 - set backlight brightness (1-16)
0xFE, 0x54 - load custom characters
0xFE, 0x55 - move screen left 1 space
0xFE, 0x56 - move screen right 1 space
0xFE, 0x61 - change BAUD rate (1 - 8)
0xFE, 0x62 - change I2C address (0-255)
0xFE, 0x70 - display version number
0xFE, 0x71 - display RS232 BAUD rate
0xFE, 0x72 - display I2C address
0xFE, 0xFE - send next byte to command register
other built-in functions:
- when either I2C or SPI is selected, the RS232 returns to 9600
BAUD rate. Vise versa, when RS232 is selected, the I2C address
returnes to 50.
- if both I2C and SPI are selected, the module will display the
firmware version number, then RS232 BAUD rate and I2C address.
each item is displayed for 2 seconds and loops continuously.
- SPI mode: normally high clock, data sampled at rising edge of
clock, Slave Select enabled.
********************************************************************/
#include <18F2321.h>
// Program memory: 4096x16 Data RAM: 512 Stack: 31
// I/O: 25 Analog Pins: 10
// Data EEPROM: 256
// C Scratch area: 00 ID Location: 2000
// Fuses: LP,XT,HS,EC,EC_IO,H4,RC_IO,INTRC_IO,INTRC,RC,FCMEN,NOFCMEN
// Fuses: NOBROWNOUT,BROWNOUT,WDT1,WDT2,WDT4,WDT8,WDT16,WDT32,WDT64
// Fuses: WDT128,WDT,NOWDT,BORV20,BORV27,BORV42,BORV45,PUT,NOPUT,CPD
// Fuses: NOCPD,NOSTVREN,STVREN,NODEBUG,DEBUG,NOLVP,LVP,WRT,NOWRT,WRTD
// Fuses: NOWRTD,CCP2C1,CCP2B3,WDT256,WDT512,WDT1024,WDT2048,WDT4096
// Fuses: WDT8192,WDT16384,WDT32768,IESO,NOIESO,EBTR,NOEBTR,EBTRB
// Fuses: NOEBTRB,MCLR,NOMCLR,PROTECT,NOPROTECT,CPB,NOCPB,WRTB,NOWRTB
// Fuses: WRTC,NOWRTC,PBADEN,NOPBADEN,BROWNOUT_SW,BROWNOUT_NOSL
// Fuses: LPT1OSC,NOLPT1OSC,XINST,NOXINST,BB256,BB512
#fuses HS,NOWDT,NOLVP,PUT,INTRC_IO,NOWDT,MCLR,NOBROWNOUT
#zero_ram
// Special Function Register definitions
#byte TOSU = 0x0FFF
#byte TOSH = 0x0FFE
#byte TOSL = 0x0FFD
#byte STKPTR = 0x0FFC
#byte PCLATU = 0x0FFB
#byte PCLATH = 0x0FFA
#byte PCL = 0x0FF9
#byte TBLPTR = 0x0FF6
#byte TBLPTRU = 0x0FF8
#byte TBLPTRH = 0x0FF7
#byte TBLPTRL = 0x0FF6
#byte TABLAT = 0x0FF5
#byte PRODH = 0x0FF4
#byte PRODL = 0x0FF3
#byte INTCON = 0x0FF2
#byte INTCON2 = 0x0FF1
#byte INTCON3 = 0x0FF0
#byte INDF0 = 0x0FEF
#byte POSTINC0 = 0x0FEE
#byte POSTDEC0 = 0x0FED
#byte PREINC0 = 0x0FEC
#byte PLUSW0 = 0x0FEB
#byte FSR0H = 0x0FEA
#byte FSR0L = 0x0FE9
#byte WREG = 0x0FE8
#byte INDF1 = 0x0FE7
#byte POSTINC1 = 0x0FE6
#byte POSTDEC1 = 0x0FE5
#byte PREINC1 = 0x0FE4
#byte PLUSW1 = 0x0FE3
#byte FSR1H = 0x0FE2
#byte FSR1L = 0x0FE1
#byte BSR = 0x0FE0
#byte INDF2 = 0x0FDF
#byte POSTINC2 = 0x0FDE
#byte POSTDEC2 = 0x0FDD
#byte PREINC2 = 0x0FDC
#byte PLUSW2 = 0x0FDB
#byte FSR2H = 0x0FDA
#byte FSR2L = 0x0FD9
#byte STATUS = 0x0FD8
#byte TMR0H = 0x0FD7
#byte TMR0L = 0x0FD6
#byte T0CON = 0x0FD5
#byte OSCCON = 0x0FD3
#byte LVDCON = 0x0FD2
#byte WDTCON = 0x0FD1
#byte RCON = 0x0FD0
#byte TMR1H = 0x0FCF
#byte TMR1L = 0x0FCE
#byte T1CON = 0x0FCD
#byte TMR2 = 0x0FCC
#byte PR2 = 0x0FCB
#byte T2CON = 0x0FCA
#byte SSPBUF = 0x0FC9
#byte SSPADD = 0x0FC8
#byte SSPSTAT = 0x0FC7
#byte SSPCON1 = 0x0FC6
#byte SSPCON2 = 0x0FC5
#byte ADRESH = 0x0FC4
#byte ADRESL = 0x0FC3
#byte ADCON0 = 0x0FC2
#byte ADCON1 = 0x0FC1
#byte ADCON2 = 0x0FC0
#byte CCPR1H = 0x0FBF
#byte CCPR1L = 0x0FBE
#byte CCP1CON = 0x0FBD
#byte CCPR2H = 0x0FBC
#byte CCPR2L = 0x0FBB
#byte CCP2CON = 0x0FBA
#byte BAUDCTL = 0x0FB8
#byte TMR3H = 0x0FB3
#byte TMR3L = 0x0FB2
#byte T3CON = 0x0FB1
#byte SPBRGH = 0x0FB0
#byte SPBRG = 0x0FAF
#byte RCREG = 0x0FAE
#byte TXREG = 0x0FAD
#byte TXSTA = 0x0FAC
#byte RCSTA = 0x0FAB
#byte EEADR = 0x0FA9
#byte EEDATA = 0x0FA8
#byte EECON2 = 0x0FA7
#byte EECON1 = 0x0FA6
#byte IPR2 = 0x0FA2
#byte PIR2 = 0x0FA1
#byte PIE2 = 0x0FA0
#byte IPR1 = 0x0F9F
#byte PIR1 = 0x0F9E
#byte PIE1 = 0x0F9D
#byte TRISC = 0x0F94
#byte TRISB = 0x0F93
#byte TRISA = 0x0F92
#byte LATC = 0x0F8B
#byte LATB = 0x0F8A
#byte LATA = 0x0F89
#byte PORTC = 0x0F82
#byte PORTB = 0x0F81
#byte PORTA = 0x0F80
#byte TRISE = 0x0F96
#byte TRISD = 0x0F95
#byte LATE = 0x0F8D
#byte LATD = 0x0F8C
#byte PORTE = 0x0F84
#byte PORTD = 0x0F83
// Bit variables associates within SFRs
#bit NEGATIVE = STATUS.4
#bit OVERFLOW = STATUS.3
#bit ZERO = STATUS.2
#bit DC = STATUS.1
#bit CARRY = STATUS.0
#bit STKFUL = STKPTR.7
#bit STKUNF = STKPTR.6
#bit SP4 = STKPTR.4
#bit SP3 = STKPTR.3
#bit SP2 = STKPTR.2
#bit SP1 = STKPTR.1
#bit SP0 = STKPTR.0
#bit GIE = INTCON.7
#bit GIEH = INTCON.7
#bit PEIE = INTCON.6
#bit GIEL = INTCON.6
#bit TMR0IE = INTCON.5
#bit INT0IE = INTCON.4
#bit RBIE = INTCON.3
#bit TMR0IF = INTCON.2
#bit INT0IF = INTCON.1
#bit RBIF = INTCON.0
#bit INT0F = INTCON.1
#bit T0IF = INTCON.2
#bit RBPU = INTCON2.7
#bit INTEDG0 = INTCON2.6
#bit INTEDG1 = INTCON2.5
#bit INTEDG2 = INTCON2.4
#bit TMR0IP = INTCON2.2
#bit RBIP = INTCON2.0
#bit T0IP = INTCON2.2
#bit INT2IP = INTCON3.7
#bit INT1IP = INTCON3.6
#bit INT2IE = INTCON3.4
#bit INT1IE = INTCON3.3
#bit INT2IF = INTCON3.1
#bit INT1IF = INTCON3.0
#bit TMR0ON = T0CON.7
#bit T08BIT = T0CON.6
#bit T0CS = T0CON.5
#bit T0SE = T0CON.4
#bit PSA = T0CON.3
#bit T0PS2 = T0CON.2
#bit T0PS1 = T0CON.1
#bit T0PS0 = T0CON.0
#bit SCS = OSCCON.0
#bit IRVST = LVDCON.5
#bit LVDEN = LVDCON.4
#bit LVV3 = LVDCON.3
#bit LVV2 = LVDCON.2
#bit LVV1 = LVDCON.1
#bit LVV0 = LVDCON.0
#bit SWDTEN = WDTCON.0
#bit IPEN = RCON.7
#bit RI = RCON.4
#bit TO = RCON.3
#bit PD = RCON.2
#bit POR = RCON.1
#bit BOR = RCON.0
#bit RD16 = T1CON.7
#bit T1RD16 = T1CON.7
#bit T1CKPS1 = T1CON.5
#bit T1CKPS0 = T1CON.4
#bit T1OSCEN = T1CON.3
#bit T1SYNC = T1CON.2
#bit TMR1CS = T1CON.1
#bit TMR1ON = T1CON.0
#bit TOUTPS3 = T2CON.6
#bit TOUTPS2 = T2CON.5
#bit TOUTPS1 = T2CON.4
#bit TOUTPS0 = T2CON.3
#bit TMR2ON = T2CON.2
#bit T2CKPS1 = T2CON.1
#bit T2CKPS0 = T2CON.0
#bit SMP = SSPSTAT.7
#bit CKE = SSPSTAT.6
#bit DA = SSPSTAT.5
#bit P = SSPSTAT.4
#bit S = SSPSTAT.3
#bit RW = SSPSTAT.2
#bit UA = SSPSTAT.1
#bit BF = SSPSTAT.0
#bit STOP = SSPSTAT.4
#bit START = SSPSTAT.3
#bit WCOL = SSPCON1.7
#bit SSPOV = SSPCON1.6
#bit SSPEN = SSPCON1.5
#bit CKP = SSPCON1.4
#bit SSPM3 = SSPCON1.3
#bit SSPM2 = SSPCON1.2
#bit SSPM1 = SSPCON1.1
#bit SSPM0 = SSPCON1.0
#bit GCEN = SSPCON2.7
#bit ACKSTAT = SSPCON2.6
#bit ACKDT = SSPCON2.5
#bit ACKEN = SSPCON2.4
#bit RCEN = SSPCON2.3
#bit PEN = SSPCON2.2
#bit RSEN = SSPCON2.1
#bit SEN = SSPCON2.0
#bit CHS3 = ADCON0.5
#bit CHS2 = ADCON0.4
#bit CHS1 = ADCON0.3
#bit CHS0 = ADCON0.2
#bit GODONE = ADCON0.1
#bit ADON = ADCON0.0
#bit ADFM = ADCON1.7
#bit ADCS2 = ADCON1.6
#bit PCFG3 = ADCON1.3
#bit PCFG2 = ADCON1.2
#bit PCFG1 = ADCON1.1
#bit PCFG0 = ADCON1.0
#bit DC1B1 = CCP1CON.5
#bit DC1B0 = CCP1CON.4
#bit CCP1M3 = CCP1CON.3
#bit CCP1M2 = CCP1CON.2
#bit CCP1M1 = CCP1CON.1
#bit CCP1M0 = CCP1CON.0
#bit DC2B1 = CCP2CON.5
#bit DC2B0 = CCP2CON.4
#bit CCP2M3 = CCP2CON.3
#bit CCP2M2 = CCP2CON.2
#bit CCP2M1 = CCP2CON.1
#bit CCP2M0 = CCP2CON.0
#bit T3RD16 = T3CON.7
#bit T3CCP2 = T3CON.6
#bit T3CKPS1 = T3CON.5
#bit T3CKPS0 = T3CON.4
#bit T3CCP1 = T3CON.3
#bit T3SYNC = T3CON.2
#bit TMR3CS = T3CON.1
#bit TMR3ON = T3CON.0
#bit CSRC = TXSTA.7
#bit TX9 = TXSTA.6
#bit TXEN = TXSTA.5
#bit SYNC = TXSTA.4
#bit BRGH = TXSTA.2
#bit TRMT = TXSTA.1
#bit TX9D = TXSTA.0
#bit SPEN = RCSTA.7
#bit RX9 = RCSTA.6
#bit SREN = RCSTA.5
#bit CREN = RCSTA.4
#bit ADDEN = RCSTA.3
#bit FERR = RCSTA.2
#bit OERR = RCSTA.1
#bit RX9D = RCSTA.0
#bit EEPGD = EECON1.7
#bit CFGS = EECON1.6
#bit EEFS = EECON1.6
#bit FREE = EECON1.4
#bit WRERR = EECON1.3
#bit WREN = EECON1.2
#bit WR = EECON1.1
#bit RD = EECON1.0
#bit EEIP = IPR2.4
#bit BCLIP = IPR2.3
#bit LVDIP = IPR2.2
#bit TMR3IP = IPR2.1
#bit CCP2IP = IPR2.0
#bit EEIF = PIR2.4
#bit BCLIF = PIR2.3
#bit LVDIF = PIR2.2
#bit TMR3IF = PIR2.1
#bit CCP2IF = PIR2.0
#bit EEIE = PIE2.4
#bit BCLIE = PIE2.3
#bit LVDIE = PIE2.2
#bit TMR3IE = PIE2.1
#bit CCP2IE = PIE2.0
#bit PSPIP = IPR1.7
#bit ADIP = IPR1.6
#bit RCIP = IPR1.5
#bit TXIP = IPR1.4
#bit SSPIP = IPR1.3
#bit CCP1IP = IPR1.2
#bit TMR2IP = IPR1.1
#bit TMR1IP = IPR1.0
#bit PSPIF = PIR1.7
#bit ADIF = PIR1.6
#bit RCIF = PIR1.5
#bit TXIF = PIR1.4
#bit SSPIF = PIR1.3
#bit CCP1IF = PIR1.2
#bit TMR2IF = PIR1.1
#bit TMR1IF = PIR1.0
#bit PSPIE = PIE1.7
#bit ADIE = PIE1.6
#bit RCIE = PIE1.5
#bit TXIE = PIE1.4
#bit SSPIE = PIE1.3
#bit CCP1IE = PIE1.2
#bit TMR2IE = PIE1.1
#bit TMR1IE = PIE1.0
#bit IBF = TRISE.7
#bit OBF = TRISE.6
#bit IBOV = TRISE.5
#bit PSPMODE = TRISE.4
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use delay(clock=8000000)
/* PORT A bits (0x0F80)*/
#bit adc_0 = PORTA.0
#bit adc_1 = PORTA.1
//#bit = PORTA.2
//#bit = PORTA.3
//#bit = PORTA.4
//#bit = PORTA.5
//#bit = PORTA.6
//#bit = PORTA.7
/* PORT B bits (0x0F81)*/
//#bit = PORTB.0
//#bit = PORTB.1
//#bit = PORTB.2
//#bit = PORTB.3
#bit spi_sel = PORTB.4
#bit i2c_sel = PORTB.5
//#bit = PORTB.6
//#bit = PORTB.7
/* PORT C bits (0x0F82)*/
#bit spi_ss = PORTC.0
#bit led = PORTC.1
//#bit spi_ss = PORTC.2
#bit sck = PORTC.3
#bit sdi = PORTC.4
#bit sdo = PORTC.5
#bit tx = PORTC.6
#bit rx = PORTC.7
#define on 1
#define off 0
#define bit short
bit serial_busy;
bit contrast_f;
bit bright_f;
char const text6[] = {"NewHaven Display"};
char const text7[] = {"Serial LCD Demo."};
/* DEFINE VARIABLES */
unsigned int tick_100m; // 100 millisecond counter
unsigned int tick_1s; // 1 second counter
unsigned int tick_wait10; // 10 millisecond delay counter
unsigned int tick_wait100; // 100 millisecond delay counter
unsigned int temp;
unsigned int tx_packet[20]; // transmit data packet
unsigned int com_mode;
unsigned int i, j;
unsigned int loop_hi, loop_lo;
unsigned int adc_result;
unsigned int contrast;
unsigned int contrast_save;
unsigned int bright;
unsigned int bright_save;
/* prototype functions */
void init_rs232(void);
void init_spi(void);
void init_i2c(void);
void lcd_cursor(unsigned int);
void lcd_clear(void);
void send_packet(unsigned int);
void i2c_busy(unsigned int);
void wait_sspif(void);
void clear_line(unsigned int);