That means I need to make my diode direction same as last time circuit design, which are 4 diode in forward direction, 4 diode in backward direction?
Thanks for your help, you really help me a lot.
I change the gnd to Vcc already,but the diode 5-8 still cannot display the number of button been pressed. Between, if i want my calliper can measure 3 input and then store and display in the lcd, what should i do?
Both projects you sent to me had the resistors connected to ground. They need to be connected to VCC or 5V, or whatever voltage the microcontroller is running from.
As far as displaying 3 values goes, you really should concentrate on displaying a single value first. This will mean that both your code and your hardware is functional.
OPTION_REG.NOT_RBPU = 0; //enable weak pull-ups on PORTB
TRISB = 0xFF; //all PBO-1(8pin) floating high *(set port B as input)*
PORTA &= 0xF0; //set the output value of pins on PEO-1 to 0 these pins are kept as inputs,excepts when one is driven low
//get ready to pull low on PEO-1
//first try pulling each pin of PEO-1 low in succession
for (i = 0; i < 4; i++)
{
TRISA = (TRISA&0xF0) | (~pow2&0x0F); //set PEO-1(4pin) as output so that it can be driven low
//set a single bit as output (forced low)
delay_us(5);
pv = PORTB;
if (pv != 0xFF)
{
for(j = 0; j < 8; j++)
{
if(!(pv & 1))
return i * 8 + j +1;
pv >>= 1;
}
}
}
Is these code means that the power was transfer from the microcontroller into PBO-1 (PORTB) , and then PBO-1 will detect which button has been pressed, then send the signal back to microcontroller through PEO-1(PORTA)?
TRISA |= 0x0F; //all PEO-1 floating high
PORTB = 0; //get ready to pull low on PBO-1
for (j = 0; j < 8; j++)
{
TRISB = ~pow2[j]; //set PBO-1 pins as output so that it can be driven low
delay_us(5);
pv = PORTA;
if (pv & 0x0F !=0x0F) //just checking if one of the PEO-1 pins have been pulled low
{
for(i = 0; i < 4; i++)
{
if(!(pv & 1))
return (i + 4) * 8 + j + 1;
pv >>= 1;
}
}
}
Is these code means the power from microcontroller transfer to the PEO-1(PORTA), and then PEO-1 detect which button was pressed, and then transfer back to the microcontroller through PBO-1(PORTB)?
I want to know, for my project, if i want to put the scanned value into equation. Do i need to convert the scanned value using ADC before I apply it into the equation?