Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

read multiple input and display corresponding digit

Status
Not open for further replies.

mailus

Full Member level 4
Full Member level 4
Joined
Mar 6, 2012
Messages
234
Helped
7
Reputation
16
Reaction score
7
Trophy points
1,308
Location
-
Visit site
Activity points
2,706
My Requirements,
i am using pic microcontroller

i have 9 inputs, output-1,display 7 segment-1(single segment).

read input from PORTC and RA0_pin.

if rc0_bit low means the display show as 1,

if rc0_bit and rc5_bit low means the display show 1 and 6 at a particular interval,

similarly for each and every combination of input the display must show the corresponding output.

i designed a program but i need to develop in different way

my program:

Code:
void main()
{
 adcon1=0x06;cmcon=0x06;
 TrisA=0x01;TrisB=0x00;TrisC=0xff;
 porta=0x00;portb=0x00;portc=0x00;
 read_input,x=0;
 do
 {
  read_input=portc^0xff;
  if(read_input==0)
  {
  x=0;
  control(x);
  portb=0x3f;
  }
  if(RC0_bit==0)
  {
  x=1;
  control(x);
  portb=0X06;
  delay_ms(1000);
  }
  if(RC1_bit==0) 
  {
  x=2;
  control(x);
  portb=0X5b;
  delay_ms(1000);
  }
  if(RC2_bit==0)
  {
  x=3;
  control(x);
  portb=0X4f;
  delay_ms(1000);
  }
  if(rc3_bit==0)
  {
  x=4;
  control(x);
  portb=0X66;
  delay_ms(1000);
  }
  if(rc4_bit==0)
  {
  x=5;
  control(x);
  portb=0X6d;
  delay_ms(1000);
  }
  if(rc5_bit==0)
  {
  x=6;
  control(x);
  portb=0X7d;
  delay_ms(1000);
  }
  if(rc6_bit==0)
  {
  x=7;
  control(x);
  portb=0X07;
  delay_ms(1000);
  }
  if(rc7_bit==0)
  {
  x=8;
  control(x);
  portb=0X7f;
  delay_ms(1000);
  }
  delay_ms(100);
  }while(1);
}
 
Last edited:

Suppose all pin low then u require to show 0 to 8 for port C & for RA0 low it is 9. For such situation I u design timer for display interval say 100 ms now i just right step.

1. After every 100 ms display update.
2. increment one counter for each time till 0 to 9
3. Sense input port & check each pin status by bit condition set variable u can direct read PORTC & store in variable bit_pos. say unsigned int bit_pos & ur input is 0, 3, 7 & 8[RA0]
then bit_pos = 0 01110110 is ur input status.
4. After each 100 ms check bit status if it is low then pass this bit location to display routine say unsigned char dis_var then for bit 0 dis_var = 0, for 3 bit pos dis_var=3 if bit is high then previous data. If no bit then pass oo or FF depend on segment type means common anode or cathode.
 

please explain with example

Sense input port & check each pin status by bit condition set variable u can direct read PORTC & store in variable bit_pos. say unsigned int bit_pos & ur input is 0, 3, 7 & 8[RA0]
but the input is random between 0~9 (portc and ra0)
by predict each and every input is tough (2^9=512)
 

It's simple
unsigned int bit_pos =0;
unsigned char temp =0;
if(RA0==0)
{
bit_pos = 0xFEFF;
}
else
{
bit_pos = 0xFFFF;
}

bit_pos = bit_pos<<9; // 1111 1110 1111 1111 or 1111 1111 1111 1111
temp = PORTC;
bit_pos = bit_pos^ temp;

switch (bit_pos)
{
case(65279):// bit RA0 action;
break;

case(65534):// bit RC0 action;
break;
so on....
}

- - - Updated - - -

It's simple
unsigned int bit_pos =0;
unsigned char temp =0;
if(RA0==0)
{
bit_pos = 0xFEFF;
}
else
{
bit_pos = 0xFFFF;
}

bit_pos = bit_pos<<9; // 1111 1110 1111 1111 or 1111 1111 1111 1111
temp = PORTC;
bit_pos = bit_pos^ temp;

switch (bit_pos)
{
case(65279):// bit RA0 action;
break;

case(65534):// bit RC0 action;
break;
so on....
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top