Hi,
I am Try to create two counters. I think I have got the counter part sorted as they now work as expected where they are broken down into individual digits that fit onto a single display but the part that I am currently struggle is to actually get that data to be display correctly. They are common Anode displays with the segments driven by two unl2003a chips, one for each row/counter. The Anode pins for each row are joined and connected an AVQ252G.
on my latest attempt I seem to have just two 0 displayed on the 1st and 4th digits while the others are not displaying anything at all.
/*
* First draft for configuring 7 segment displays as part of counter project
*
* The Hardware consist of two banks of 5 seven segment displays, each row is controlled seperately by its
* own matrice. The type used for this project are common anode. A prototyping board is used to arrange the
* connections from the Arduino into 3 jst connnects. The anode connections are brought out in the first
* header. The other two provide the individual segment connections for each row respectively.
* connector provides the the annodes for all the displays. The other two provide the individual segment
* connections for each row respectively. currently this just checks for input and increments the counter.
* Once first stage testing has been done a reeal time clock will need to be factored in so that the daily
* count resets. Finally got work as intended however there are issues refreshing the display fast enough
* so may need to rethink and impment a timer instead.
*
* The mapping is as follows
*
* Connector 1 [Common Anodes]:
*
* D16 | PH1 | 6
* D6 | PH3 | 7
* D7 | PH4 | 8
* D8 | PH5 | 9
* D9 | PH6 | 10
*
*
*
* |ROW1_D1|ROW1_D2|ROW1_D3|ROW1_D4|ROW1_D5|
* -----------------------------------------
* |ROW2_D1|ROW2_D2|ROW2_D3|ROW2_D4|ROW2_D5|
*
* Connector 2 [Row 1 segment connections]:
*
* Pin | Port|Segment
* D31 | PC6 | a
* D32 | PC5 | b
* D33 | PC4 | c
* D34 | PC3 | d
* D35 | PC2 | e
* D36 | PC1 | f
* D37 | PC0 | g
*
*
*
* |D31 - PC6|D32 - PC5|D33 - PC4|D34 - PC3|D35 - PC2|D36 -PC1|D37 - PC0|
* ----------------------------------------------------------------------
*
* Connector 3 [Row 2 segment connections]:
*
*Pin | Port|Segment
* D43 | PL6 | a
* D44 | PL5 | b
* D45 | PL4 | c
* D46 | PL3 | d
* D47 | PL2 | e
* D48 | PL1 | f
* D49 | PL0 | g
*
*
*
*/
#include <TimerOne.h>
/* Variables to handle the display data */
//Format as a,b,c,d,e,f,g, dot
//number, in the format 0, 1, 2, 3, 4, 5, 6, 7, 8 ,9
volatile byte numbers[10]={0x7E,0x30,0x6D,0x79,0x33,0x5B,0x5F,0x70,0x7F,0x73};
volatile byte row_sel[5]={0x02,0x08,0x10,0x20,0x40}; //Cycle through each column
volatile byte seg_reset = 0x00; //clear all outputs before going to the display
//volatile byte filter;
//volatile byte output;
volatile int seg_num = 0; //hold the current position of the display
volatile int pos;
unsigned long display_counter;
unsigned long display_counter_past;
volatile bool switch_digit = false;
int day_unit = 0;
int day_ten = 0;
int day_hun = 0;
int day_thou = 0;
int day_ten_thou = 0;
int tot_unit = 0;
int tot_ten = 0;
int tot_hun = 0;
int tot_thou = 0;
int tot_ten_thou = 0;
//Store the digit data into five columns to match the number of displays that we have.
volatile int display_data[2][5]={{day_unit, day_ten, day_hun, day_thou, day_ten_thou}, //Hold the data for the daily counter
{tot_unit, tot_ten, tot_hun, tot_thou, tot_ten_thou}}; //Hold the data for the total counter
long int daily_counter;
long int daily_counter_prev;
long int total_counter;
/* Variables to deal with our input sources */
const int trigger1 = 18;
const int trigger2 = 19;
const int reset_but = 2; //place holder for RTC impelemention later
//int trig1_prev = HIGH;
//int trig2_prev = HIGH;
//unsigned long trig1_tracker;
//unsigned long trig2_tracker;
//unsigned long debounceDelay = 100;
//bool trig1_state;
//bool trig2_state;
void setup() {
// put your setup code here, to run once:
//DDRE |= 0b00111011; //Matrix the Annode pin to control a whole column effectively
DDRH |= 0xFA; //Config annode pins shared by each row of displays
DDRC |= 0x7F; //configure segement pins for daily counter
DDRL |= 0X7F; //configure segement pins for daily counter
Timer1.initialize(15000);
Timer1.attachInterrupt(display_ref); // blinkLED to run every 0.15 seconds
//attachInterrupt(digitalPinToInterrupt(trigger1),tray_handler1, LOW);
//attachInterrupt(digitalPinToInterrupt(trigger2),tray_handler2, LOW);
//pinMode(trigger1, INPUT);
//pinMode(trigger2, INPUT);
//pinMode(reset_but, INPUT);
Serial.begin(19200);
Serial.println("initalising");
}
void loop() {
/*
int aLoaded = digitalRead(trigger1); //Final input may not be very clean so need to include some debounce handling as well
// If the switch changed, due to noise or pressing:
if (aLoaded != trig1_prev) {
// reset the debouncing timer
trig1_tracker = millis();
}
if ((millis() - trig1_tracker) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:
// if the button state has changed:
if (aLoaded != trig1_state) {
trig1_state = aLoaded;
}
}
int bLoaded = digitalRead(trigger2); //Final input may not be very clean so need to include some debounce handling as well
// If the switch changed, due to noise or pressing:
if (bLoaded != trig2_prev) {
// reset the debouncing timer
trig2_tracker = millis();
}
if ((millis() - trig2_tracker) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:
// if the button state has changed:
if (bLoaded != trig2_state) {
trig2_state = bLoaded;
}
}
if(trig1_state == LOW){
Serial.print("Line 1 active: ");
Serial.println(daily_counter);
daily_counter++;
}
if(trig2_state == LOW){
Serial.print("Line 2 active: ");
Serial.println(daily_counter);
daily_counter++;
}
*/
noInterrupts();
int pos_loop = pos;
Serial.println(pos_loop);
interrupts();
daily_counter++;
delay(3000);
fetch_daily();
fetch_total();
}
void display_ref(void){
//Write out our data store in the array to each of the digits
for(pos;pos < 4;pos++){
PORTC = seg_reset; //Clear any number before writing the digit
PORTL = seg_reset;
PORTH = seg_reset;
PORTH = row_sel[pos]; //Prepare for next row
PORTC = numbers[display_data[0][pos]]; //Print out each digit for the daily counter
PORTL = numbers[display_data[1][pos]]; //Print out each digit for total counter
}
pos = 0; //Reset the cycle ready for the next loop
}
void process_data(int rowSel, long int counter){
//Take data from the daily counter and break down into indivial numbers for each display
//The row select is use to determine if we are process for the daily count or the total
//count.
int digit_5 =((counter/10000) % 10);
display_data[rowSel][4] = digit_5; //If the counter is 10,000 or great then assign a number to the 5th digit
int digit_4 = ((counter/1000) % 10);
display_data[rowSel][3] = digit_4;
int digit_3 = ((counter/100) % 10);
display_data[rowSel][2] = digit_3;
int digit_2 = ((counter/10) % 10);
display_data[rowSel][1] = digit_2;
int digit_1 = (counter%10);
display_data[rowSel][0] = digit_1;
}
void fetch_daily(){
if(daily_counter > 99999){
daily_counter = 0; //Reset upon overflow
}
process_data(0, daily_counter);
//Print statements themporary for debugging only
Serial.println("TTH, TH, H, T, U");
Serial.print(display_data[0][4]);
Serial.print(",");
Serial.print(display_data[0][3]);
Serial.print(",");
Serial.print(display_data[0][2]);
Serial.print(",");
Serial.print(display_data[0][1]);
Serial.print(",");
Serial.println(display_data[0][0]);
daily_counter_prev = daily_counter;
}
void fetch_total(){
if(total_counter == 0){
total_counter == daily_counter;
}
else if(total_counter > 99999){
total_counter = 0;
}
else{
total_counter = total_counter + (daily_counter - daily_counter_prev);
}
process_data(1, total_counter);
Serial.println("TTH, TH, H, T, U");
Serial.print(display_data[0][4]);
Serial.print(",");
Serial.print(display_data[0][3]);
Serial.print(",");
Serial.print(display_data[0][2]);
Serial.print(",");
Serial.print(display_data[0][1]);
Serial.print(",");
Serial.println(display_data[0][0]);
}
Grateful for any replies
Cheers
Ryzer





