CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

lcd117_e.c compiling

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Harley Engholm



Joined: 08 May 2015
Posts: 3

View user's profile Send private message

lcd117_e.c compiling
PostPosted: Fri May 08, 2015 11:03 am     Reply with quote

I am trying to compile a .c file provided by Wulfden which is the code for the open use of the lcd117_e firmware for lcd serial use. The information at the beginning of the code indicates the use of the ccs compiler is required. I have tried to compile this code without success as there are numerous errors. My compiler is the PCWHD, IDE version 5.026 Limited Evaluation. The info on this version is that it is fully functional for 45 days. The files can be downloaded at http://www.wulfden.org/TheShoppe/k107/pha/pha.shtml
Don't know how to use the code display, but the first list is the .c file and the second listing is the include DEFS_1827.H file. Any help would be appreciated.


// -------------------------------------------------------------------
// LCD117_E ( requires CCS PIC-C Compiler )
//
// copyright, Peter H Anderson, East Corinth, VT, July, '03
//
// Nov 10, '04 - Corrected error on cursor type command. Was not saving to
// EEPROM. Added ?+ and ?- commands to enable and disable startup display.
// Reduced delay on boot.
//
// This adds big number and other capabilities. - April 2, '06
//
// Change chip fromm 16F648A to 16F1827 - LCD117.D - PHA - '10
//
// Release LCD117.D source code under MIT license as LCD117.E with
// minor fix to EEPROM code - estate of PHA and BBR - May '13
// ---------------------------------------------------------------------

/**************************************************************************
* Copyright (c) <2013> - estate of Peter H. Anderson
* Eric Anderson, Brian B. Riley, Paul Badger
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
**************************************************************************/

/**************************************************************************
* The Peter Anderson code released here under MIT License is essentially
* Peter's source code for the LCD117.D firmware release _UNTOUCHED_ save
* for two exceptions
* (1) - the firmware parameter display has been edited to reflect "LCD117.E"
* (2) - there is a quirk in the CCS compiler with regard to how it writes
* strings to EEPROMs using he "#rom" directive. See the code correction
* and comments in the vicinity of line 1630
*
* BBR, Underhill Center,VT -- 22 May 2013
**************************************************************************/

#case

#device PIC16F1827 *=16

//#define FINAL

#ifdef DEVELOP

#device ICD=TRUE
#rom 0x8007 = {0x09e4, 0x0003} // Manual Section 4.0

#endif

#ifdef FINAL
#rom 0x8007 = {0x095c, 0x1610}
#endif

#fuses INTRC_IO, WDT, PUT, MCLR, PROTECT, NOCPD, NOBROWNOUT, NOCLKOUT
#fuses NOIESO, NOFCMEN, WRT, STVREN, NODEBUG, NOLVP

//#define _19200
#define _9600
//#define _4800
//#define _2400
//#define _1200
//#define _300

#define _20X4
//#define _16X2

#include <defs_1827.h>
#include <string.h>

// timing routines - 4 MHz clock
void delay_10us(byte t);
void delay_ms(long t);

void lcd_init(void);
void lcd_clr(void);
void lcd_char(byte c);
void lcd_char_test(byte c);
void lcd_cmd_byte(byte c);
void lcd_data_nibble(byte c, byte delay);
void lcd_cmd_nibble(byte c);
void lcd_clr_line(byte line);
void lcd_cursor_pos(byte line, byte pos);
void lcd_line_feed(void);
void lcd_reverse_line_feed(void);
void lcd_CR(void);

void lcd_set_cursor_style(byte v);

void lcd_non_destructive_back_space(void);
void lcd_destructive_back_space(void);
void lcd_increment_cursor_pos(void);
void lcd_control_sequence(void);

void lcd_cursor_home(void);
void lcd_tab(void);
void lcd_beep(void);

void lcd_write_user_chars(void);
void lcd_write_big_num_patts(void);

void lcd_big3_num(char ch);
void lcd_big4_num(char ch);
// serial routines
void asynch_enable(void);
void asynch_disable(void);


void open_ser_com(void);
void close_ser_com(void); // never used
byte get_rx_buff(byte *ch_ptr);
void reset_rx_buff(void);

char num_to_char(byte val);

byte get_char(void);
byte ser_get_hex2(byte *p);

// eeprom routines
void put_byte_eeprom(byte adr, byte d);
byte get_byte_eeprom(byte adr);

void put_bytes_eeprom(byte adr, byte *pd, byte num_bytes);

// check these
#define EN porta7 // for LCD control lines
#define RS porta6

#define SUCCESS !0
#define FAILURE 0

#define POSITIVE 1
#define MINUS 0

#define TRUE !0
#define FALSE 0

#define EESTART 0xf000

#define RX_BUFF_MAX 64 // for serial routines - 32 byte buffer
#define RX_BUFF_FULL 3

#define S_C_START_ADR 0x00
#define TAB_ADR 0x40
#define CURSOR_ADR 0x41

#define NUM_LINES_ADR 0x42
#define NUM_COLS_ADR 0x43

#define BACKLIGHT_ADR 0x44
#define START_UP_ADR 0x45

#define CUSTOM_START 0x46
#define CUSTOM_LINE_0 0x46
#define CUSTOM_LINE_1 0x46 + 20
#define CUSTOM_LINE_2 0x46 + 40
#define CUSTOM_LINE_3 0x46 + 60


#define MK_LONG(h, l) ((unsigned long)(h) << 8) | (l)

//#define DUMMY // used for debugging

const byte _0_mask[8] = {0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f};
const byte _1_mask[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};

// for lcd
byte num_cols, num_lines;

byte big_num3_flag;
byte big_num4_flag;

byte current_line, current_col;
byte tab_size;

// for receipt of RS232 serial
byte rx_buff_full, rx_put_index, rx_get_index;
byte rx_buff[RX_BUFF_MAX];

// for timing routine
byte t_10us;

void main(void)
{
byte ch, x, n, row, col;

OSCCON = 0x6b; // 4.0 MHz interal
ANSELA = 0x00;
ANSELB = 0x00;

ccp1sel = 0; // on RB3
rxdtsel = 0; // RB1

//#ifdef DEFER

if (not_por == 0)
{
delay_ms(300);
not_por = 1;
while(1) ; // wait for watch dog timeout
}
//#endif

// configure terminals for LCD

PORTA = 0x00;
TRISA = 0x00;

EN = 0;
RS = 0;

//wpub2 = 1;
WPUB = 0x04;
wpuen_ = 0;

PORTB = 0x00;
TRISB = 0x06; // all except RB2 and RB1

// test routine
if (portb2 == 0)
{
delay_ms(300); // ######## Nov 11
while(1)
{
//#ifdef DEFER
if (not_por == 0)
{
not_por = 1;
while(1) ; // wait for watch dog timeout
}
//#endif
lcd_init();
lcd_cmd_byte(0x06); // increment cursor
delay_ms(2);
lcd_set_cursor_style(3);
for (n=32; n<128; n++)
{
if(n != '?')
{
lcd_char_test(n);
delay_ms(250);
}
}
}
}


// else
peie = 1; gie = 1;
big_num3_flag = FALSE;
big_num4_flag = FALSE;

delay_ms(150);
lcd_init();
lcd_cmd_byte(0x06); // increment cursor
x = get_byte_eeprom(CURSOR_ADR);
lcd_set_cursor_style(x);
num_lines = get_byte_eeprom(NUM_LINES_ADR);
num_cols = get_byte_eeprom(NUM_COLS_ADR);
tab_size = get_byte_eeprom(TAB_ADR);
lcd_write_user_chars();


// configure CCP1 for PWM operation
portb3 = 0;
trisb3 = 0;
PR2 = 0xff;
T2CON = 0x04; // timer 2 on

CCP1CON = 0x0c; // PWM Mode

CCPR1L = get_byte_eeprom(BACKLIGHT_ADR);

x = get_byte_eeprom(START_UP_ADR);
x = x;
if (x==1)
{
lcd_clr_line(0);
#ifdef _19200
printf(lcd_char, "#117E 192 ");
#endif
#ifdef _9600
printf(lcd_char, "#117E 96 ");
#endif
#ifdef _4800
printf(lcd_char, "#117E 48 ");
#endif
#ifdef _2400
printf(lcd_char, "#117E 24 ");
#endif
printf(lcd_char, "%1dX%2d", num_lines, num_cols);
lcd_clr_line(1);
printf(lcd_char, "%d ", tab_size);

for (n=0; n<8; n++) // display the special characters
{
lcd_char(n);
}
lcd_cursor_pos(1, 9);


lcd_char(' ');
printf(lcd_char, "%2x", CCPR1L);
//lcd_char(' ');
delay_ms(2000);
}

if (x == 2)
{
for (row = 0; row < num_lines; row++)
{
lcd_clr_line(row);
for (col = 0; col < num_cols; col++)
{
ch = get_byte_eeprom(CUSTOM_START + row * num_cols + col);
lcd_char(ch);
}
}
delay_ms(2000);
}


//#ifdef FINAL

lcd_clr();


open_ser_com();

while(1)
{
ch = get_char();
if (ch == 0xfe)
{
ch = get_char();
lcd_cmd_byte(ch);
delay_ms(2);
}
else if (ch == '?')
{
lcd_control_sequence();
}
else if ((ch >= 32) && (ch <= 128)) // ignore special characters
{
if (big_num3_flag == TRUE)
{
if ((ch >= '0') && (ch <= '9'))
{
lcd_big3_num(ch); //<<<<<<<<<<<<<<<<<<<<<<<
}
else if ((ch == '.') || (ch==':') || (ch=='-'))
{
lcd_big3_num(ch); //<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
else
{
// do nothing
}
}
else if (big_num4_flag == TRUE)
{

if ((ch >= '0') && (ch <= '9'))
{
lcd_big4_num(ch);
}
else if ((ch == '.') || (ch==':') || (ch=='-'))
{
lcd_big4_num(ch);
}
else
{
// do nothing
}
}
else
{
lcd_char(ch);
lcd_increment_cursor_pos();
}
}
else
{
}
}
//#endif
}

void delay_10us(byte t)
{
t_10us = t;
#asm

DELAY_10US_1:
CLRWDT
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ t_10us, F
GOTO DELAY_10US_1
#endasm
}

void delay_ms(long t) // delays t millisecs
{
do
{
delay_10us(99);
} while(--t);
}

void lcd_control_sequence(void)
{
byte n, x, y, v, row, col;
byte ch, ch1;
byte vals[8];
byte custom_chars[20];

ch = get_char();

if ((ch >= '0') && (ch <='7'))
{
// write special character to LCD
x = ch - '0';
lcd_char(x);
lcd_increment_cursor_pos();
}

else
{

switch(ch)
{
case 'a': // home cursor
lcd_cursor_home();
delay_ms(2);
break;

case 'b': // destructive backspace
lcd_destructive_back_space();
break;

case 'c': // cursor style
ch1 = get_char();
x = ch1 - '0';
if ((x>=0) && (x<4))
{
lcd_set_cursor_style(x);
put_byte_eeprom(CURSOR_ADR, x);
}
break;
case 'f':
lcd_clr();
//delay_ms(2);
break;

case 'g': // beep
lcd_beep();
break;


case 'G': // set geometry
ch1 = get_char();
x = ch1 - '0';
if ((x >= 2) && (x <=4)) // num_lines
{
ch1 = get_char(); // first digit of num_cols
y = ch1 - '0';
if ((y>=1) && (y<=4))
{
v = y;
}
else
{
break;
}

ch1 = get_char(); // second digit of num_cols
y = ch1 - '0';
if ((y>=0) && (y<=9))
{
v = v * 10 + y;
}
else
{
break;
}
num_lines = x;
num_cols = v;
put_byte_eeprom(NUM_LINES_ADR, num_lines);
put_byte_eeprom(NUM_COLS_ADR, num_cols);
}
break;

case 'B': // set backlight
if (ser_get_hex2(&v) == SUCCESS)
{
CCPR1L = v;
put_byte_eeprom(BACKLIGHT_ADR, v);
break;
}
else
{
break;
}

case 'h':
lcd_non_destructive_back_space();
break;

case 'i': lcd_increment_cursor_pos();
break;

case 'I':
if (ser_get_hex2(&v) == SUCCESS)
{
if ((v>=0) && (v<=3))
{
lcd_char(v);
}
}
break;

case 'j':
lcd_line_feed();
break;

case 'k':
lcd_reverse_line_feed();
break;

case 'l':
lcd_clr_line(current_line);
break;


case 'm':
lcd_CR();
break;

case 'n':
lcd_CR();
lcd_line_feed();
lcd_clr_line(current_line);
break;

case 's': // set horizonatal tab size
ch1 = get_char();
x = ch1 - '0';
if ((x>0) && (x<9))
{
tab_size = x;
put_byte_eeprom(TAB_ADR, tab_size);
}

break;

case 't': tab_size = get_byte_eeprom(TAB_ADR); // probably an overkill
lcd_tab();
break;

case 'x': // cursor_col
ch1 = get_char();
v = 0x00;
x = ch1 - '0';
#ifdef OLD
if ((x == 0) || (x == 1))
#endif
if ((x>=0) && (x<=3))
{
v = x;
ch1 = get_char();
x = ch1 - '0';
if ((x>=0) && (x<=9))
{
v = v*10 + x;
}
else
{
break;
}
lcd_cursor_pos(current_line, v);
break;
}
break;

case 'y': // cursor_line
ch1 = get_char();
x = ch1 - '0';
if ((x>=0) && (x<4))
{
lcd_cursor_pos(x, current_col);
}
break;

case '!': // command char to LCD
if (ser_get_hex2(&v) == SUCCESS)
{
lcd_cmd_byte(v);
}
break;


case '?': lcd_char('?');
lcd_increment_cursor_pos();
break;

case 'D': // define special character
ch1 = get_char();
x = ch1 - '0';
if (!((x >=0) && (x<=7))) // number is outside range
{
break;
}

for (n=0; n<8; n++)
{
if (ser_get_hex2(&v) == SUCCESS)
{
vals[n] = v;
}
else
{
break;
}
}

// now save vals to EEPROM for special character x
put_bytes_eeprom(S_C_START_ADR + 8 * x, vals, 8);
lcd_write_user_chars(); // also send to LCD RAM
break;

case 'H':
case 'L':
ch1 = get_char();
x = ch1 - '0';
if (!((x >=4) && (x<=7))) // number is outside range
{
break;
}

TRISB = TRISB & _0_mask[x];
if (ch == 'H')
{
PORTB = PORTB | _1_mask[x];
}
else
{
PORTB = PORTB & _0_mask[x];
}
break;
#ifdef OLD
case '+': // turn on startup message ######################
put_byte_eeprom(START_UP_ADR, 0x01);
break;

case '-': // turn off startup message
put_byte_eeprom(START_UP_ADR, 0x00);
break;
#endif
// ################################### added, Nov 10,
case 'S':
ch1 = get_char();
x = ch1 - '0';
if (!((x >=0) && (x<=2))) // number is outside range
{
break;
}
put_byte_eeprom(START_UP_ADR, x);
break;


case '>': // turn on big characters
ch1 = get_char();
x = ch1 - '0';
if (x == 3)
{
big_num3_flag = TRUE;
big_num4_flag = FALSE;
lcd_write_big_num_patts();
break;
}
else if (x==4)
{
big_num4_flag = TRUE;
big_num3_flag = FALSE;
lcd_write_big_num_patts();
break;
}
else
{
break;
}

case '<':
big_num3_flag = FALSE;
big_num4_flag = FALSE;
break;

case 'R': // restore default custom characters
lcd_write_user_chars();
break;

case '*': // display custom screen, Mar, '05
for (row = 0; row < num_lines; row++)
{
lcd_clr_line(row);
for (col = 0; col < num_cols; col++)
{
ch = get_byte_eeprom(CUSTOM_START + row * num_cols + col);
lcd_char(ch);
}
}
current_line = 0; current_col = 0;
break;

case 'C': // custom line definition, Mar, '05
ch1 = get_char();
row = ch1 - '0';
if (!((row >=0) && (row<=3))) // number is outside range
{
break;
}
lcd_cursor_pos(row, 0);
for (col=0; col<num_cols; col++)
{
ch = get_char();
custom_chars[col] = ch;
lcd_cursor_pos(row, col);
lcd_char(ch);
}
for (col = 0; col<num_cols; col++)
{
put_byte_eeprom(CUSTOM_START + row * num_cols + col, custom_chars[col]);
}

current_line = 0; current_col = 0;
lcd_cursor_pos(current_line, current_col);
break;


default: break;
}
}
}

void lcd_big3_num(char ch)
{

const byte _09[10][12] = {{4, 2, 5, 1, 0, 1, 1, 0, 1, 6, 3, 7}
{4, 1, 0, 0, 1, 0, 0, 1, 0, 3, 1, 3}
{4, 2, 5, 0, 4, 7, 4, 7, 0, 1, 3, 3}
{4, 2, 5, 0, 4, 7, 0, 6, 5, 6, 3, 7}
{0, 4, 1, 4, 7, 1, 2, 2, 1, 0, 0, 1}
{1, 2, 7, 1, 0, 0, 2, 2, 5, 6, 3, 7}
{4, 2, 5, 1, 0, 0, 1, 2, 5, 6, 3, 7}
{2, 2, 1, 0, 4, 7, 4, 7, 0, 1, 0, 0}
{4, 2, 5, 6, 3, 7, 4, 2, 5, 6, 3, 7}
{4, 2, 5, 1, 0, 1, 6, 2, 1, 6, 3, 7}};

// const b[16]
byte col, row, num_index;

if ((ch >='0') && (ch<='9'))
{
num_index = ch - '0';

for (row=0; row<4; row++)
{
lcd_cursor_pos(row, current_col);
for(col = 0; col < 4; col++)
{
if (col == 3)
{
lcd_char(0);
}
else
{
lcd_char(_09[num_index][3*row + col]);
//delay_ms(250);
//lcd_increment_cursor_pos();
}
}
}

current_col = current_col + 4;
}
else if (ch == '.')
{
for(row = 0; row<4; row++)
{
lcd_cursor_pos(row, current_col);
for (col = 0; col < 2; col++)
{
if((col == 0) && (row == 3))
{
lcd_char(3);
}
else
{
lcd_char(0);
}
}
}
current_col = current_col + 2;
}
else if (ch == '-')
{
for(row = 0; row<4; row++)
{
lcd_cursor_pos(row, current_col);
for (col = 0; col < 2; col++)
{
if((col == 0) && (row == 2))
{
lcd_char(2);
}
else
{
lcd_char(0);
}
}
}
current_col = current_col + 2;
}

else // its a colon
{
for(row = 0; row<4; row++)
{
lcd_cursor_pos(row, current_col);
for (col = 0; col < 2; col++)
{
if((col == 0) && (row == 1))
{
lcd_char(2);
}
else if((col == 0) && (row == 2))
{
lcd_char(3);
}
else
{
lcd_char(0);
}
}
}
current_col = current_col + 2;

}
if (current_col > 19)
{
current_col = 0;
}
current_line = 0;
lcd_cursor_pos(current_line, current_col);

}

void lcd_big4_num(char ch)
{

const byte _09[10][16] = {{4, 2, 2, 5, 1, 0, 0, 1, 1, 0, 0, 1, 6, 3, 3, 7}
{0, 4, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3, 1, 3}
{4, 2, 2, 5, 0, 0, 4, 7, 0, 4, 7, 0, 1, 3, 3, 3}
{4, 2, 2, 5, 0, 0, 4, 7, 0, 0, 6, 5, 6, 3, 3, 7}
{0, 4, 7, 1, 4, 7, 0, 1, 1, 3, 3, 1, 0, 0, 0, 1}
{1, 2, 2, 2, 6, 3, 3, 5, 0, 0, 0, 1, 6, 3, 3, 7}
{1, 2, 2, 0, 1, 3, 3, 5, 1, 0, 0, 1, 6, 3, 3, 7}
{2, 2, 2, 4, 0, 0, 4, 7, 0, 4, 7, 0, 1, 0, 0, 0}
{4, 2, 2, 5, 6, 3, 3, 7, 4, 2, 2, 5, 6, 3, 3, 7}
{4, 2, 2, 5, 1, 0, 0, 1, 6, 2, 2, 1, 0, 3, 3, 7}};

// const b[16]
byte col, row, num_index;

if ((ch >='0') && (ch<='9'))
{
num_index = ch - '0';

for (row=0; row<4; row++)
{
lcd_cursor_pos(row, current_col);
for(col = 0; col < 5; col++)
{
if (col == 4)
{
lcd_char(0);
}
else
{
lcd_char(_09[num_index][4*row + col]);
//delay_ms(250);
//lcd_increment_cursor_pos();
}
}
}

current_col = current_col + 5;
}
else if (ch == '.')
{
for(row = 0; row<4; row++)
{
lcd_cursor_pos(row, current_col);
for (col = 0; col < 2; col++)
{
if((col == 0) && (row == 3))
{
lcd_char(3);
}
else
{
lcd_char(0);
}
}
}
current_col = current_col + 2;
}
else if (ch == '-')
{
for(row = 0; row<4; row++)
{
lcd_cursor_pos(row, current_col);
for (col = 0; col < 2; col++)
{
if((col == 0) && (row == 2))
{
lcd_char(2);
}
else
{
lcd_char(0);
}
}
}
current_col = current_col + 2;
}

else // its a colon
{
for(row = 0; row<4; row++)
{
lcd_cursor_pos(row, current_col);
for (col = 0; col < 2; col++)
{
if((col == 0) && (row == 1))
{
lcd_char(2);
}
else if((col == 0) && (row == 2))
{
lcd_char(3);
}
else
{
lcd_char(0);
}
}
}
current_col = current_col + 2;

}
if (current_col > 19)
{
current_col = 0;
}
current_line = 0;
lcd_cursor_pos(current_line, current_col);

}

// LCD routines
void lcd_char(byte c) // displays ASCII character c to LCD
{
lcd_data_nibble(c>>4, 0); // high byte followed by low
lcd_data_nibble(c&0x0f, 0);
delay_10us(7);
}

void lcd_char_test(byte c) // displays ASCII character c to LCD
{
lcd_data_nibble(c>>4, 1); // high byte followed by low
lcd_data_nibble(c&0x0f, 1);
delay_ms(1);
}

void lcd_data_nibble(byte c, byte delay) // RS is at logic one for data
{
EN = 0; // clock;
RS = 1;

PORTA = (PORTA & 0xf0) | c;
EN = 1;
if(delay)
{
delay_ms(25); // test mode
}
EN = 0;
if(delay)
{
delay_ms(25); // test mode
}
}

void lcd_cmd_byte(byte c) // used for sending byte commands
{
lcd_cmd_nibble(c>>4); // high byte followed by low
lcd_cmd_nibble(c&0x0f);
delay_10us(7);
}

void lcd_cmd_nibble(byte c) // RS is at logic zero for commands
{
EN = 0; // clock;
RS = 0;

PORTA = (PORTA & 0xf0) | c;
EN = 1;
EN = 0;
}

void lcd_init(void)
{

PORTA = 0x00;
TRISA = 0x00;
lcd_cmd_nibble(0x03); // configure LCD in 4-bit transfer mode
delay_ms(5);
lcd_cmd_nibble(0x03);
delay_ms(5);
lcd_cmd_nibble(0x03);
delay_ms(5);
lcd_cmd_nibble(0x02);
delay_ms(5);
lcd_cmd_byte(0x01);
delay_ms(5);
current_line = 0; current_col = 0;
}


void lcd_clr(void) // clear LCD and cursor to upper left
{
lcd_cmd_byte(0x01);
delay_ms(2);
current_line = 0; current_col = 0;
}

void lcd_clr_line(byte line) // clear indicated line and leave
// cursor at the beginning of the line
{
byte n;
lcd_cursor_pos(line, 0);
for (n=0; n<num_cols; n++)
{
lcd_char(' ');
}
lcd_cursor_pos(line, 0);
current_line = line; current_col = 0;
}

void lcd_cursor_pos(byte line, byte pos)
{
const byte a[4] = {0x80, 0xc0, 0x80, 0xc0};
// start address for the two lines
if ((line == 0) || (line == 1))
{
lcd_cmd_byte(a[line]+pos);
}

else
{
lcd_cmd_byte(a[line] + num_cols + pos);
}
current_line = line; current_col = pos;
}

void lcd_line_feed(void)
{
++current_line;
if (current_line > (num_lines - 1))
{
current_line = 0;
}

lcd_cursor_pos(current_line, current_col);
}

void lcd_reverse_line_feed(void)
{
if (current_line == 0)
{
current_line = num_lines - 1;
}

else
{
--current_line;
}
lcd_cursor_pos(current_line, current_col);
}

void lcd_CR(void)
{
current_col = 0;
lcd_cursor_pos(current_line, current_col);
}

void lcd_non_destructive_back_space(void)
{
if (current_col == 0)
{
if (current_line == 0)
{
current_line = num_lines - 1;
}

else
{
--current_line;
}

current_col = num_cols - 1;
}
else
{
-- current_col;
}
lcd_cursor_pos(current_line, current_col);
}

void lcd_destructive_back_space(void)
{
lcd_non_destructive_back_space();
lcd_char(" ");
lcd_increment_cursor_pos();
lcd_non_destructive_back_space();
}

void lcd_set_cursor_style(byte v)
{
lcd_cmd_byte(0x0c+v);
}

void lcd_cursor_home(void)
{
lcd_cursor_pos(0, 0);
current_line = 0; current_col = 0;
}

void lcd_increment_cursor_pos(void)
{
++current_col;
if (current_col > (num_cols-1))
{
current_col = 0;
++current_line;
if (current_line > (num_lines - 1))
{
current_line = 0;
}
}
lcd_cursor_pos(current_line, current_col);
}

void lcd_tab(void)
{
byte n;

if (current_col >= (num_cols-1)) // already at end of line
{
// do nothing
}

else if (((current_col) % tab_size) == 0) // currently at a tab set
{
for (n=0; n<tab_size; n++)
{
if (current_col >= (num_cols-1)) // at end of line
{
break;
}
lcd_char(' ');
lcd_increment_cursor_pos();
}
}
else
{
for (n=0; ; n++)
{
if (current_col >= (num_cols-1)) // at end of line
{
break;
}

else
{
if (((current_col) % tab_size) == 0)
{
break;
}
lcd_char(' ');
lcd_increment_cursor_pos();
}
}
}
}

void lcd_write_user_chars(void) // write all user characters to LCD
{
byte char_num, n, x;

for (char_num = 0; char_num < 8; char_num++)
{

lcd_cmd_byte(0x40 + 8 * char_num); // set CGRAM to address 0x00 + 8 * char_num

for (n=0; n<8; n++)
{
x = get_byte_eeprom(8 * char_num + n);
lcd_char(x);
}
delay_ms(5);
}
lcd_cursor_pos(current_line, current_col); // return to regular mode
}

void lcd_write_big_num_patts(void) // write big character patts to LCD
{
byte char_num, n, x;
// big character patts
const byte big[8][8] = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x00},
{0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x00},
{0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x1f, 0x00},
{0x00, 0x10, 0x18, 0x1c, 0x1e, 0x1f, 0x1f, 0x00},
{0x1f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00, 0x00},
{0x1f, 0x1f, 0x1e, 0x1c, 0x18, 0x10, 0x00, 0x00}};


for (char_num = 0; char_num < 8; char_num++)
{

lcd_cmd_byte(0x40 + 8 * char_num); // set CGRAM to address 0x00 + 8 * char_num

for (n=0; n<8; n++)
{
x = big[char_num][n];
lcd_char(x);
}
delay_ms(5);
}
lcd_cursor_pos(current_line, current_col); // return to regular mode
}

void lcd_beep(void)
{
byte n;
portb0 = 0;
trisb0 = 0;

for(n = 0; n<25; n++)
{
portb0=1;
delay_10us(100);
portb0=0;
delay_10us(100);
}
}

///////////////// Serial Routines

void asynch_enable(void)
{

rxdtsel = 0; // RX to RB1

sync = 0; // asynchronous

brgh = 1;
brg16 = 1;

#ifdef _300
SSPRGH = 13;
SPBRGL = 4; // 13 * 256 + 4 = 3332
#endif

#ifdef _19200
SPBRGH = 0;
SPBRGL = 51;
#endif

#ifdef _9600
SPBRGH = 0;
SPBRGL = 103;
#endif

#ifdef _4800
SPBRGH = 0;
SPBRGL = 205; // <<<<<<<<<<<<<<<<<< check this
#endif

#ifdef _2400
SPBRGH = 1;
SPBRGL = 160; // 1 * 256 + 160 = 416
#endif

#ifdef _1200
SPBRGH = 3;
SPBRGL = 64;
#endif

spen = 1; // serial port enabled
cren = 1;
trisb1 = 1;

}

void asynch_disable(void)
{
cren = 0;
spen = 0;
}


void reset_rx_buff(void)
{
char ch;
rx_put_index = 0;
rx_get_index = 0;
rx_buff_full = FALSE;
ch = RCREG; // get any junk that may be in the buffer
ch = RCREG;

rcif = 0;
rcie = 1;
peie = 1;
gie = 1;
}

void open_ser_com(void)
{
char ch;

asynch_enable();
rx_put_index = 0;
rx_get_index = 0;
rx_buff_full = FALSE;
ch = RCREG; // get any junk that may be in the buffer
ch = RCREG;

rcif = 0;
rcie = 1;

}

void close_ser_com(void)
{
rcie = 0;
rcif = 0;
}


byte get_char(void)
{
byte ch, error_code;

// cren=0;
cren=1;
rcif=0;


while((error_code = get_rx_buff(&ch)) == FAILURE) // no character
{
//#ifdef DEFER
if (not_por == 0)
{
not_por = 1;
while(1) ; // wait for watch dog timeout
}
//#endif

#asm
CLRWDT
#endasm

}

if (error_code == RX_BUFF_FULL)
{
return(0); // no meaning
}


else if (error_code == SUCCESS)
{
return(ch);
}

else
{
return(0); // unexplained
}
}


byte get_rx_buff(byte *ch_ptr) // fetch a character
{
byte error_code;
#asm
CLRWDT
#endasm
if (rx_buff_full == TRUE)
{
rx_buff_full = FALSE;
error_code = RX_BUFF_FULL; // overflow of rx_buff
rx_put_index = 0;
rx_get_index = 0;
*ch_ptr = 0; // buff was full. returned character has no meaning
}
else if (rx_get_index == rx_put_index) // there is no character
{
error_code = FAILURE; // no character
*ch_ptr = 0;
}
else
{
*ch_ptr = rx_buff[rx_get_index];
++rx_get_index;
if (rx_get_index >= RX_BUFF_MAX)
{
rx_get_index = 0; // wrap
}
error_code = SUCCESS; // success
}
return(error_code);
}

byte ser_get_hex2(byte *p) // clean this up
{
byte ch, x, v;
ch = get_char();
if ((ch >= '0') && (ch<='9'))
{
x = ch - '0';
}
else if ((ch >='a') && (ch <='f'))
{
x = ch - 'a' + 10;
}
else if ((ch >='A') && (ch <='F'))
{
x = ch - 'A' + 10;
}
else
{
return(FAILURE);
}
v = x;
ch = get_char();
if ((ch >= '0') && (ch <='9'))
{
x = ch - '0';
}
else if ((ch >='a') && (ch <='f'))
{
x = ch - 'a' + 10;
}
else if ((ch >='A') && (ch <='F'))
{
x = ch - 'A' + 10;
}
else
{
return(FAILURE);
}
v = v*16 + x;
*p = v;
return(SUCCESS);
}

void put_byte_eeprom(byte adr, byte d)
{
byte intcon_save; // n=20;

cfgs = 0;
eepgd = 0;

EEADRL = adr;
EEDATL = d;


intcon_save = INTCON;

while(gie)
{
gie = 0;
}
eeif = 0;
peie = 1;
eeie = 1;

wren = 1;
EECON2 = 0x55;
EECON2 = 0xaa;
wr = 1; // begin programming sequence
wren = 0;
while(wr)
{
}
eeie = 0;
eeif = 0;
INTCON = intcon_save;
gie = 1;
}

void put_bytes_eeprom(byte adr, byte *pd, byte num_bytes)
{
byte n;
for (n=0; n<num_bytes; ++n, ++adr, ++pd)
{
put_byte_eeprom(adr, *pd);
}
}


byte get_byte_eeprom(byte adr)
{
byte x;
cfgs = 0;
eepgd = 0;
EEADRL = adr;
rd = 1;
#asm
NOP
NOP
NOP
NOP
NOP
#endasm
x = EEDATL;
return(x);
}



#int_rda
void rda_interrupt_handler(void)
{
if (rx_buff_full == FALSE)
{
rx_buff[rx_put_index] = RCREG; // fetch the character
++rx_put_index;
if (rx_put_index >= RX_BUFF_MAX)
{
rx_put_index = 0; // wrap around
}
if (rx_put_index == rx_get_index)
{
rx_buff_full = TRUE;
}
}
}

#int_default
void default_interrupt_handler(void)
{
}


// special characters
#rom EESTART+0x00 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f}
#rom EESTART+0x08 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f}
#rom EESTART+0x10 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f}
#rom EESTART+0x18 = {0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f}
#rom EESTART+0x20 = {0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}
#rom EESTART+0x28 = {0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}
#rom EESTART+0x30 = {0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}
#rom EESTART+0x38 = {0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}



#rom EESTART + TAB_ADR = {4} // tab
#rom EESTART + CURSOR_ADR = {3} // curson on and blinking
#rom EESTART + BACKLIGHT_ADR = {0}
#rom EESTART + START_UP_ADR = {1} // ########## Nov 10, '04



#ifdef _20X4

#rom EESTART + NUM_LINES_ADR = {4}
#rom EESTART + NUM_COLS_ADR = {20}

#endif

#ifdef _16X2

#rom EESTART + NUM_LINES_ADR = {2}
#rom EESTART + NUM_COLS_ADR = {16}

#endif

// Due to a quirk in CCS compiler, this declaration must be left in
// one long line. If broken up as in "JUNK" below, it will compile clean,
// BUT, CCSLOAD will not burn the chip ... it will fail - BBR - May '13

#rom EESTART + CUSTOM_LINE_0 = {"abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST0123456789012345678998765432109876543210"}

#ifdef JUNK
#rom EESTART + CUSTOM_LINE_0 = {"abcdefghijklmnopqrst"}
#rom EESTART + CUSTOM_LINE_1 = {"ABCDEFGHIJKLMNOPQRST"}
#rom EESTART + CUSTOM_LINE_2 = {"01234567890123456789"}
#rom EESTART + CUSTOM_LINE_3 = {"98765432109876543210"}
#endif

#ifdef JUNK
#rom EESTART + CUSTOM_LINE_0 = {" "}
#rom EESTART + CUSTOM_LINE_1 = {" "}
#rom EESTART + CUSTOM_LINE_2 = {" "}
#rom EESTART + CUSTOM_LINE_3 = {" "}
#endif



#ifdef JUNK
// big character patts - no longer stored in EEPROM
#rom EESTART + 0x80 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
#rom EESTART + 0x80 = {0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}
#rom EESTART + 0x80 = {0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00}
#rom EESTART + 0x80 = {0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}
#rom EESTART + 0x80 = {0x01, 0x03, 0x07, 0x07, 0x0f, 0x0f, 0x1f, 0x1f}
#rom EESTART + 0x80 = {0x10, 0x18, 0x18, 0x1c, 0x1c, 0x1e, 0x1f, 0x1f}
#rom EESTART + 0x80 = {0x1f, 0x0f, 0x07, 0x07, 0x03, 0x03, 0x01, 0x01}
#rom EESTART + 0x80 = {0x1f, 0x1e, 0x1c, 0x1c, 0x18, 0x18, 0x10, 0x10}

#endif
]// -------------------------------------------------------------------
// LCD117_E ( requires CCS PIC-C Compiler )
//
// copyright, Peter H Anderson, East Corinth, VT, July, '03
//
// Nov 10, '04 - Corrected error on cursor type command. Was not saving to
// EEPROM. Added ?+ and ?- commands to enable and disable startup display.
// Reduced delay on boot.
//
// This adds big number and other capabilities. - April 2, '06
//
// Change chip fromm 16F648A to 16F1827 - LCD117.D - PHA - '10
//
// Release LCD117.D source code under MIT license as LCD117.E with
// minor fix to EEPROM code - estate of PHA and BBR - May '13
// ---------------------------------------------------------------------

/**************************************************************************
* Copyright (c) <2013> - estate of Peter H. Anderson
* Eric Anderson, Brian B. Riley, Paul Badger
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
**************************************************************************/

/**************************************************************************
* The Peter Anderson code released here under MIT License is essentially
* Peter's source code for the LCD117.D firmware release _UNTOUCHED_ save
* for two exceptions
* (1) - the firmware parameter display has been edited to reflect "LCD117.E"
* (2) - there is a quirk in the CCS compiler with regard to how it writes
* strings to EEPROMs using he "#rom" directive. See the code correction
* and comments in the vicinity of line 1630
*
* BBR, Underhill Center,VT -- 22 May 2013
**************************************************************************/

#case

#device PIC16F1827 *=16

//#define FINAL

#ifdef DEVELOP

#device ICD=TRUE
#rom 0x8007 = {0x09e4, 0x0003} // Manual Section 4.0

#endif

#ifdef FINAL
#rom 0x8007 = {0x095c, 0x1610}
#endif

#fuses INTRC_IO, WDT, PUT, MCLR, PROTECT, NOCPD, NOBROWNOUT, NOCLKOUT
#fuses NOIESO, NOFCMEN, WRT, STVREN, NODEBUG, NOLVP

//#define _19200
#define _9600
//#define _4800
//#define _2400
//#define _1200
//#define _300

#define _20X4
//#define _16X2

#include <defs_1827.h>
#include <string.h>

// timing routines - 4 MHz clock
void delay_10us(byte t);
void delay_ms(long t);

void lcd_init(void);
void lcd_clr(void);
void lcd_char(byte c);
void lcd_char_test(byte c);
void lcd_cmd_byte(byte c);
void lcd_data_nibble(byte c, byte delay);
void lcd_cmd_nibble(byte c);
void lcd_clr_line(byte line);
void lcd_cursor_pos(byte line, byte pos);
void lcd_line_feed(void);
void lcd_reverse_line_feed(void);
void lcd_CR(void);

void lcd_set_cursor_style(byte v);

void lcd_non_destructive_back_space(void);
void lcd_destructive_back_space(void);
void lcd_increment_cursor_pos(void);
void lcd_control_sequence(void);

void lcd_cursor_home(void);
void lcd_tab(void);
void lcd_beep(void);

void lcd_write_user_chars(void);
void lcd_write_big_num_patts(void);

void lcd_big3_num(char ch);
void lcd_big4_num(char ch);
// serial routines
void asynch_enable(void);
void asynch_disable(void);


void open_ser_com(void);
void close_ser_com(void); // never used
byte get_rx_buff(byte *ch_ptr);
void reset_rx_buff(void);

char num_to_char(byte val);

byte get_char(void);
byte ser_get_hex2(byte *p);

// eeprom routines
void put_byte_eeprom(byte adr, byte d);
byte get_byte_eeprom(byte adr);

void put_bytes_eeprom(byte adr, byte *pd, byte num_bytes);

// check these
#define EN porta7 // for LCD control lines
#define RS porta6

#define SUCCESS !0
#define FAILURE 0

#define POSITIVE 1
#define MINUS 0

#define TRUE !0
#define FALSE 0

#define EESTART 0xf000

#define RX_BUFF_MAX 64 // for serial routines - 32 byte buffer
#define RX_BUFF_FULL 3

#define S_C_START_ADR 0x00
#define TAB_ADR 0x40
#define CURSOR_ADR 0x41

#define NUM_LINES_ADR 0x42
#define NUM_COLS_ADR 0x43

#define BACKLIGHT_ADR 0x44
#define START_UP_ADR 0x45

#define CUSTOM_START 0x46
#define CUSTOM_LINE_0 0x46
#define CUSTOM_LINE_1 0x46 + 20
#define CUSTOM_LINE_2 0x46 + 40
#define CUSTOM_LINE_3 0x46 + 60


#define MK_LONG(h, l) ((unsigned long)(h) << 8) | (l)

//#define DUMMY // used for debugging

const byte _0_mask[8] = {0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f};
const byte _1_mask[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};

// for lcd
byte num_cols, num_lines;

byte big_num3_flag;
byte big_num4_flag;

byte current_line, current_col;
byte tab_size;

// for receipt of RS232 serial
byte rx_buff_full, rx_put_index, rx_get_index;
byte rx_buff[RX_BUFF_MAX];

// for timing routine
byte t_10us;

void main(void)
{
byte ch, x, n, row, col;

OSCCON = 0x6b; // 4.0 MHz interal
ANSELA = 0x00;
ANSELB = 0x00;

ccp1sel = 0; // on RB3
rxdtsel = 0; // RB1

//#ifdef DEFER

if (not_por == 0)
{
delay_ms(300);
not_por = 1;
while(1) ; // wait for watch dog timeout
}
//#endif

// configure terminals for LCD

PORTA = 0x00;
TRISA = 0x00;

EN = 0;
RS = 0;

//wpub2 = 1;
WPUB = 0x04;
wpuen_ = 0;

PORTB = 0x00;
TRISB = 0x06; // all except RB2 and RB1

// test routine
if (portb2 == 0)
{
delay_ms(300); // ######## Nov 11
while(1)
{
//#ifdef DEFER
if (not_por == 0)
{
not_por = 1;
while(1) ; // wait for watch dog timeout
}
//#endif
lcd_init();
lcd_cmd_byte(0x06); // increment cursor
delay_ms(2);
lcd_set_cursor_style(3);
for (n=32; n<128; n++)
{
if(n != '?')
{
lcd_char_test(n);
delay_ms(250);
}
}
}
}


// else
peie = 1; gie = 1;
big_num3_flag = FALSE;
big_num4_flag = FALSE;

delay_ms(150);
lcd_init();
lcd_cmd_byte(0x06); // increment cursor
x = get_byte_eeprom(CURSOR_ADR);
lcd_set_cursor_style(x);
num_lines = get_byte_eeprom(NUM_LINES_ADR);
num_cols = get_byte_eeprom(NUM_COLS_ADR);
tab_size = get_byte_eeprom(TAB_ADR);
lcd_write_user_chars();


// configure CCP1 for PWM operation
portb3 = 0;
trisb3 = 0;
PR2 = 0xff;
T2CON = 0x04; // timer 2 on

CCP1CON = 0x0c; // PWM Mode

CCPR1L = get_byte_eeprom(BACKLIGHT_ADR);

x = get_byte_eeprom(START_UP_ADR);
x = x;
if (x==1)
{
lcd_clr_line(0);
#ifdef _19200
printf(lcd_char, "#117E 192 ");
#endif
#ifdef _9600
printf(lcd_char, "#117E 96 ");
#endif
#ifdef _4800
printf(lcd_char, "#117E 48 ");
#endif
#ifdef _2400
printf(lcd_char, "#117E 24 ");
#endif
printf(lcd_char, "%1dX%2d", num_lines, num_cols);
lcd_clr_line(1);
printf(lcd_char, "%d ", tab_size);

for (n=0; n<8; n++) // display the special characters
{
lcd_char(n);
}
lcd_cursor_pos(1, 9);


lcd_char(' ');
printf(lcd_char, "%2x", CCPR1L);
//lcd_char(' ');
delay_ms(2000);
}

if (x == 2)
{
for (row = 0; row < num_lines; row++)
{
lcd_clr_line(row);
for (col = 0; col < num_cols; col++)
{
ch = get_byte_eeprom(CUSTOM_START + row * num_cols + col);
lcd_char(ch);
}
}
delay_ms(2000);
}


//#ifdef FINAL

lcd_clr();


open_ser_com();

while(1)
{
ch = get_char();
if (ch == 0xfe)
{
ch = get_char();
lcd_cmd_byte(ch);
delay_ms(2);
}
else if (ch == '?')
{
lcd_control_sequence();
}
else if ((ch >= 32) && (ch <= 128)) // ignore special characters
{
if (big_num3_flag == TRUE)
{
if ((ch >= '0') && (ch <= '9'))
{
lcd_big3_num(ch); //<<<<<<<<<<<<<<<<<<<<<<<
}
else if ((ch == '.') || (ch==':') || (ch=='-'))
{
lcd_big3_num(ch); //<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
else
{
// do nothing
}
}
else if (big_num4_flag == TRUE)
{

if ((ch >= '0') && (ch <= '9'))
{
lcd_big4_num(ch);
}
else if ((ch == '.') || (ch==':') || (ch=='-'))
{
lcd_big4_num(ch);
}
else
{
// do nothing
}
}
else
{
lcd_char(ch);
lcd_increment_cursor_pos();
}
}
else
{
}
}
//#endif
}

void delay_10us(byte t)
{
t_10us = t;
#asm

DELAY_10US_1:
CLRWDT
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ t_10us, F
GOTO DELAY_10US_1
#endasm
}

void delay_ms(long t) // delays t millisecs
{
do
{
delay_10us(99);
} while(--t);
}

void lcd_control_sequence(void)
{
byte n, x, y, v, row, col;
byte ch, ch1;
byte vals[8];
byte custom_chars[20];

ch = get_char();

if ((ch >= '0') && (ch <='7'))
{
// write special character to LCD
x = ch - '0';
lcd_char(x);
lcd_increment_cursor_pos();
}

else
{

switch(ch)
{
case 'a': // home cursor
lcd_cursor_home();
delay_ms(2);
break;

case 'b': // destructive backspace
lcd_destructive_back_space();
break;

case 'c': // cursor style
ch1 = get_char();
x = ch1 - '0';
if ((x>=0) && (x<4))
{
lcd_set_cursor_style(x);
put_byte_eeprom(CURSOR_ADR, x);
}
break;
case 'f':
lcd_clr();
//delay_ms(2);
break;

case 'g': // beep
lcd_beep();
break;


case 'G': // set geometry
ch1 = get_char();
x = ch1 - '0';
if ((x >= 2) && (x <=4)) // num_lines
{
ch1 = get_char(); // first digit of num_cols
y = ch1 - '0';
if ((y>=1) && (y<=4))
{
v = y;
}
else
{
break;
}

ch1 = get_char(); // second digit of num_cols
y = ch1 - '0';
if ((y>=0) && (y<=9))
{
v = v * 10 + y;
}
else
{
break;
}
num_lines = x;
num_cols = v;
put_byte_eeprom(NUM_LINES_ADR, num_lines);
put_byte_eeprom(NUM_COLS_ADR, num_cols);
}
break;

case 'B': // set backlight
if (ser_get_hex2(&v) == SUCCESS)
{
CCPR1L = v;
put_byte_eeprom(BACKLIGHT_ADR, v);
break;
}
else
{
break;
}

case 'h':
lcd_non_destructive_back_space();
break;

case 'i': lcd_increment_cursor_pos();
break;

case 'I':
if (ser_get_hex2(&v) == SUCCESS)
{
if ((v>=0) && (v<=3))
{
lcd_char(v);
}
}
break;

case 'j':
lcd_line_feed();
break;

case 'k':
lcd_reverse_line_feed();
break;

case 'l':
lcd_clr_line(current_line);
break;


case 'm':
lcd_CR();
break;

case 'n':
lcd_CR();
lcd_line_feed();
lcd_clr_line(current_line);
break;

case 's': // set horizonatal tab size
ch1 = get_char();
x = ch1 - '0';
if ((x>0) && (x<9))
{
tab_size = x;
put_byte_eeprom(TAB_ADR, tab_size);
}

break;

case 't': tab_size = get_byte_eeprom(TAB_ADR); // probably an overkill
lcd_tab();
break;

case 'x': // cursor_col
ch1 = get_char();
v = 0x00;
x = ch1 - '0';
#ifdef OLD
if ((x == 0) || (x == 1))
#endif
if ((x>=0) && (x<=3))
{
v = x;
ch1 = get_char();
x = ch1 - '0';
if ((x>=0) && (x<=9))
{
v = v*10 + x;
}
else
{
break;
}
lcd_cursor_pos(current_line, v);
break;
}
break;

case 'y': // cursor_line
ch1 = get_char();
x = ch1 - '0';
if ((x>=0) && (x<4))
{
lcd_cursor_pos(x, current_col);
}
break;

case '!': // command char to LCD
if (ser_get_hex2(&v) == SUCCESS)
{
lcd_cmd_byte(v);
}
break;


case '?': lcd_char('?');
lcd_increment_cursor_pos();
break;

case 'D': // define special character
ch1 = get_char();
x = ch1 - '0';
if (!((x >=0) && (x<=7))) // number is outside range
{
break;
}

for (n=0; n<8; n++)
{
if (ser_get_hex2(&v) == SUCCESS)
{
vals[n] = v;
}
else
{
break;
}
}

// now save vals to EEPROM for special character x
put_bytes_eeprom(S_C_START_ADR + 8 * x, vals, 8);
lcd_write_user_chars(); // also send to LCD RAM
break;

case 'H':
case 'L':
ch1 = get_char();
x = ch1 - '0';
if (!((x >=4) && (x<=7))) // number is outside range
{
break;
}

TRISB = TRISB & _0_mask[x];
if (ch == 'H')
{
PORTB = PORTB | _1_mask[x];
}
else
{
PORTB = PORTB & _0_mask[x];
}
break;
#ifdef OLD
case '+': // turn on startup message ######################
put_byte_eeprom(START_UP_ADR, 0x01);
break;

case '-': // turn off startup message
put_byte_eeprom(START_UP_ADR, 0x00);
break;
#endif
// ################################### added, Nov 10,
case 'S':
ch1 = get_char();
x = ch1 - '0';
if (!((x >=0) && (x<=2))) // number is outside range
{
break;
}
put_byte_eeprom(START_UP_ADR, x);
break;


case '>': // turn on big characters
ch1 = get_char();
x = ch1 - '0';
if (x == 3)
{
big_num3_flag = TRUE;
big_num4_flag = FALSE;
lcd_write_big_num_patts();
break;
}
else if (x==4)
{
big_num4_flag = TRUE;
big_num3_flag = FALSE;
lcd_write_big_num_patts();
break;
}
else
{
break;
}

case '<':
big_num3_flag = FALSE;
big_num4_flag = FALSE;
break;

case 'R': // restore default custom characters
lcd_write_user_chars();
break;

case '*': // display custom screen, Mar, '05
for (row = 0; row < num_lines; row++)
{
lcd_clr_line(row);
for (col = 0; col < num_cols; col++)
{
ch = get_byte_eeprom(CUSTOM_START + row * num_cols + col);
lcd_char(ch);
}
}
current_line = 0; current_col = 0;
break;

case 'C': // custom line definition, Mar, '05
ch1 = get_char();
row = ch1 - '0';
if (!((row >=0) && (row<=3))) // number is outside range
{
break;
}
lcd_cursor_pos(row, 0);
for (col=0; col<num_cols; col++)
{
ch = get_char();
custom_chars[col] = ch;
lcd_cursor_pos(row, col);
lcd_char(ch);
}
for (col = 0; col<num_cols; col++)
{
put_byte_eeprom(CUSTOM_START + row * num_cols + col, custom_chars[col]);
}

current_line = 0; current_col = 0;
lcd_cursor_pos(current_line, current_col);
break;


default: break;
}
}
}

void lcd_big3_num(char ch)
{

const byte _09[10][12] = {{4, 2, 5, 1, 0, 1, 1, 0, 1, 6, 3, 7}
{4, 1, 0, 0, 1, 0, 0, 1, 0, 3, 1, 3}
{4, 2, 5, 0, 4, 7, 4, 7, 0, 1, 3, 3}
{4, 2, 5, 0, 4, 7, 0, 6, 5, 6, 3, 7}
{0, 4, 1, 4, 7, 1, 2, 2, 1, 0, 0, 1}
{1, 2, 7, 1, 0, 0, 2, 2, 5, 6, 3, 7}
{4, 2, 5, 1, 0, 0, 1, 2, 5, 6, 3, 7}
{2, 2, 1, 0, 4, 7, 4, 7, 0, 1, 0, 0}
{4, 2, 5, 6, 3, 7, 4, 2, 5, 6, 3, 7}
{4, 2, 5, 1, 0, 1, 6, 2, 1, 6, 3, 7}};

// const b[16]
byte col, row, num_index;

if ((ch >='0') && (ch<='9'))
{
num_index = ch - '0';

for (row=0; row<4; row++)
{
lcd_cursor_pos(row, current_col);
for(col = 0; col < 4; col++)
{
if (col == 3)
{
lcd_char(0);
}
else
{
lcd_char(_09[num_index][3*row + col]);
//delay_ms(250);
//lcd_increment_cursor_pos();
}
}
}

current_col = current_col + 4;
}
else if (ch == '.')
{
for(row = 0; row<4; row++)
{
lcd_cursor_pos(row, current_col);
for (col = 0; col < 2; col++)
{
if((col == 0) && (row == 3))
{
lcd_char(3);
}
else
{
lcd_char(0);
}
}
}
current_col = current_col + 2;
}
else if (ch == '-')
{
for(row = 0; row<4; row++)
{
lcd_cursor_pos(row, current_col);
for (col = 0; col < 2; col++)
{
if((col == 0) && (row == 2))
{
lcd_char(2);
}
else
{
lcd_char(0);
}
}
}
current_col = current_col + 2;
}

else // its a colon
{
for(row = 0; row<4; row++)
{
lcd_cursor_pos(row, current_col);
for (col = 0; col < 2; col++)
{
if((col == 0) && (row == 1))
{
lcd_char(2);
}
else if((col == 0) && (row == 2))
{
lcd_char(3);
}
else
{
lcd_char(0);
}
}
}
current_col = current_col + 2;

}
if (current_col > 19)
{
current_col = 0;
}
current_line = 0;
lcd_cursor_pos(current_line, current_col);

}

void lcd_big4_num(char ch)
{

const byte _09[10][16] = {{4, 2, 2, 5, 1, 0, 0, 1, 1, 0, 0, 1, 6, 3, 3, 7}
{0, 4, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3, 1, 3}
{4, 2, 2, 5, 0, 0, 4, 7, 0, 4, 7, 0, 1, 3, 3, 3}
{4, 2, 2, 5, 0, 0, 4, 7, 0, 0, 6, 5, 6, 3, 3, 7}
{0, 4, 7, 1, 4, 7, 0, 1, 1, 3, 3, 1, 0, 0, 0, 1}
{1, 2, 2, 2, 6, 3, 3, 5, 0, 0, 0, 1, 6, 3, 3, 7}
{1, 2, 2, 0, 1, 3, 3, 5, 1, 0, 0, 1, 6, 3, 3, 7}
{2, 2, 2, 4, 0, 0, 4, 7, 0, 4, 7, 0, 1, 0, 0, 0}
{4, 2, 2, 5, 6, 3, 3, 7, 4, 2, 2, 5, 6, 3, 3, 7}
{4, 2, 2, 5, 1, 0, 0, 1, 6, 2, 2, 1, 0, 3, 3, 7}};

// const b[16]
byte col, row, num_index;

if ((ch >='0') && (ch<='9'))
{
num_index = ch - '0';

for (row=0; row<4; row++)
{
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 08, 2015 12:19 pm     Reply with quote

You didn't have to post the code. You gave the link.

To fix the compilation problems, you need to put a comma at the end
of each block in braces (except the last one). I have done this, as shown below:
Code:
void lcd_big4_num(char ch)
{

  const byte _09[10][16] = {{4, 2, 2, 5, 1, 0, 0, 1, 1, 0, 0, 1, 6, 3, 3, 7},
                          {0, 4, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3, 1, 3},
                          {4, 2, 2, 5, 0, 0, 4, 7, 0, 4, 7, 0, 1, 3, 3, 3},
                          {4, 2, 2, 5, 0, 0, 4, 7, 0, 0, 6, 5, 6, 3, 3, 7},
                          {0, 4, 7, 1, 4, 7, 0, 1, 1, 3, 3, 1, 0, 0, 0, 1},
                          {1, 2, 2, 2, 6, 3, 3, 5, 0, 0, 0, 1, 6, 3, 3, 7},
                          {1, 2, 2, 0, 1, 3, 3, 5, 1, 0, 0, 1, 6, 3, 3, 7},
                          {2, 2, 2, 4, 0, 0, 4, 7, 0, 4, 7, 0, 1, 0, 0, 0},
                          {4, 2, 2, 5, 6, 3, 3, 7, 4, 2, 2, 5, 6, 3, 3, 7},
                          {4, 2, 2, 5, 1, 0, 0, 1, 6, 2, 2, 1, 0, 3, 3, 7}};


Do the same thing here, as shown below. I have added a comma
at the end of each block of 8, after the closing brace. Except the last one.
Code:

void lcd_write_big_num_patts(void)   // write big character patts to LCD
{
   byte char_num, n, x;
// big character patts
const byte big[8][8] = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
                           {0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x00},
                           {0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00},
                           {0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x00},
                           {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x1f, 0x00},
                           {0x00, 0x10, 0x18, 0x1c, 0x1e, 0x1f, 0x1f, 0x00},
                           {0x1f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00, 0x00},
                           {0x1f, 0x1f, 0x1e, 0x1c, 0x18, 0x10, 0x00, 0x00}};
Harley Engholm



Joined: 08 May 2015
Posts: 3

View user's profile Send private message

PostPosted: Sat May 09, 2015 9:01 am     Reply with quote

Thanks for the quick response. It does compile with some warnings but can be loaded to the pic. The program does not function properly, but it is probably something built into the code. Thanks again.
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Sat May 09, 2015 11:04 am     Reply with quote

As posted, it is setup to compile for use with an ICD.
Look at what removing the REM in front of the line #define FINAL does.
Harley Engholm



Joined: 08 May 2015
Posts: 3

View user's profile Send private message

PostPosted: Sat May 09, 2015 11:24 am     Reply with quote

I have been working with the code etc. and it does work and it appears I had a setup issue when using a picaxe 08M. I will continue to work with the code and will post anything I find to help others.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group