Help with 2.5 Digit 7-Segment LCD Code

Status
Not open for further replies.

dkw

New Member
The following code was compiled in CCS and counts from 0-9 w/ output to the following LCD (Common Cathode)

https://www.electro-tech-online.com/custompdfs/2013/04/LCD-S2X1C50TR.pdf

This code works but I'm trying to make two modifications:

1) Add a second digit without multiplexing
2) Substitute a 2 or 3 digit variable instead of the counter

The PIC has a built in LCD controller (16F914)

Any help in terms of how this might be coded would be greatly appreciated.

Thanks!

Code:
/*  Connections
Seg   Port   
A1 – RC1
B1 – RC2
C1 – RC4
D1 – RC3
E1 – RB4
F1 – RB1
G1 – RB0

A2 – RD1
B2 – RD7
C2 – RD4
D2 – RD3
E2 – RD5
F2 – RD6
G2 – RD0
1BC – RD6
Com/Cath - Gnd
*/
#include <16F914.h>
#use delay (clock=4000000) // oscillator frequency for delay_ms()

/***** CONFIGURATION *****/
// ext reset, no code protect, no watchdog, 4 MHz int clock
#fuses MCLR,NOPROTECT,NOWDT,INTRC_IO

/***** LOOKUP TABLES *****/

// pattern table for 7 segment display on ports B and C
const int8 pat7seg[10] = {
// RC4:1,RB4,RB1:0 = CDBAEFG
0b1111110, // 0
0b1010000, // 1
0b0111101, // 2
0b1111001, // 3
0b1010011, // 4
0b1101011, // 5
0b1101111, // 6
0b1011000, // 7
0b1111111, // 8
0b1111011 // 9
}; 
/***** MAIN PROGRAM *****/
void main()
{
unsigned int8 digit; // digit to be displayed
//*** Initialization
// configure ports
setup_adc_ports(NO_ANALOGS); // disable all analog and comparator inputs
setup_comparator(NC_NC_NC_NC); // -> RB0, RB1, RC0, RC1 digital

//*** Main loop
while (TRUE)
{
// display each digit from 0 to 9 for 1 sec
for (digit = 0; digit < 20; digit++)
{
// display digit by extracting pattern bits for all pins
output_b((pat7seg[digit] & 1<<2) << 2 | // RB4
(pat7seg[digit] & 0b00000011)); // RB0-1
output_c((pat7seg[digit] >> 2) & 0b011110); // RC1-4
// delay 1 sec
delay_ms(1000);
} 
}
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…