Has anyone run into this problem before? I am using almost all the I/O pins as digital outputs to drive an LCD display directly. As a demo I have a counter going from 00 to 99 and it works fine. I am using digital pins 0-17 except for the crystal pins. I have to use three of the analog pins as digital outputs.
When I try to read from analog pin 6, one of the segments (tied to d2) goes blank and does not switch! I cannot figure this one out! Below is the code. I know it's not pretty but I am just starting out with this stuff.
My biggest problem is I don't know if this is a hardware or software bug. My next step is to use the AVR ISP programmer to try and load the bootloader into another 168 and see if it does the same thing. Lots of learning to do.
BTW, this is a boarduino.
Thanks for any help!
Moby
// LCD pin map
//
// ------- ---8--- ---1---
// 13| |9 6| |2
// | | | |
// --14--- ---7---
// 12| |10 5| |3
// | | | |
// ------- --11--- ---4---
// ASCII to LCD element map
unsigned char LCD_ascii_to_elements[] =
{
0x7e, // '0'
0x0c, // '1'
0xb6, // '2
0x9e, // '3
0xcc, // '4
0xda, // '5
0xfa, // '6
0x0e, // '7
0xfe, // '8
0xce // '9'
};
// LCD element to chip pin map
unsigned int LCD_elements_to_pins[] =
{ //element
2, //1
1, //2
15, //3
14, //4
16, //5
3, //6
4, //7
12, //8
5, //9
8, //10
9, //11
10, //12
6, //13
7 //14
};
int i;
int j;
int k;
int digit;
int del;
int temp;
unsigned char nibble_lo;
unsigned char nibble_hi;
unsigned int mask;
unsigned char ones;
unsigned char tens;
void setup() // run once, when the sketch starts
{
for(i=0;i<=17;++i){
pinMode(i, OUTPUT); // sets the digital pin as output
}
pinMode(PC6, INPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
j=0;
del=10000;
digit=0;
for(;;){
++j;
if(j>=15){
j=0;
temp = analogRead(PC6);
temp = temp/10;
++digit;
if(digit>99){digit=0;}
} else {
ones=0;
tens=0;
for(k=0;k<=digit;++k){
++ones;
if(ones>9){
ones=0;
++tens;
}
if (tens>9) tens = 0;
}
nibble_lo = LCD_ascii_to_elements[ones];
nibble_hi = LCD_ascii_to_elements[tens];
digitalWrite(0, LOW); // sets the common low
mask = 0x02;
for(k=0;k<=6;++k){ // set the one bit on
if(nibble_lo & mask){
digitalWrite(LCD_elements_to_pins[k], HIGH); // sets the LCD on
} else {
digitalWrite(LCD_elements_to_pins[k], LOW); // sets the LCD off
}
mask <<= 1;
}
mask = 0x02;
for(k=7;k<=14;++k){ // set the one bit on
if(nibble_hi & mask){
digitalWrite(LCD_elements_to_pins[k], HIGH); // sets the LCD on
} else {
digitalWrite(LCD_elements_to_pins[k], LOW); // sets the LCD off
}
mask <<= 1;
}
delayMicroseconds(del); // waits for a second
digitalWrite(0, HIGH); // sets the common low
mask = 0x02;
for(k=0;k<=6;++k){ // set the one bit on
if(nibble_lo & mask){
digitalWrite(LCD_elements_to_pins[k], LOW); // sets the LCD on
} else {
digitalWrite(LCD_elements_to_pins[k], HIGH); // sets the LCD off
}
mask <<= 1;
}
mask = 0x02;
for(k=7;k<=14;++k){ // set the one bit on
if(nibble_hi & mask){
digitalWrite(LCD_elements_to_pins[k], LOW); // sets the LCD on
} else {
digitalWrite(LCD_elements_to_pins[k], HIGH); // sets the LCD off
}
mask <<= 1;
}
delayMicroseconds(del); // waits for a second
}
}
}