dimanche 4 avril 2021

How can I use switch statements to display number on a 7-segment display?

So, this might be a microntroller question, but I have trouble with the code, so I thought there may be someone who can at least give me a hint to all this. I am trying connect a potentiometer to a 7segment display, which takes in 2V(minimum) to 3.3V (maximum). How can I connect the ATD (potentiometer) value to switch cases?

void light7segment(unsigned int cnt)       //convert ATD value
{
 
    
}

The code above is a function that will take in the ATD value and use the case statement from set_7segment() in light7segment.

void main ()
{
  unsigned int i;
  
 
    //Insert Application Software Here
    for (;;){     
    i= Atd0.atddr[8].d10;       //get ATD value
     
    light7segment(i);   // display ATD value on 7-seg
    
    }
        
    for (;;);
}




void set_7segment(unsigned char number) 
{
  switch (number) 
  {
    case 0 : 
      Pim.pth.byte=0b00111111;      //display 0 in 7-seg
      break;  
    case 1 : 
      Pim.pth.byte=0b00000110;      //display 1 in 7-seg
      break;
    case 2 : 
      Pim.pth.byte=0b01011011;      //display 2 in 7-seg
      break;
    case 3 : 
      Pim.pth.byte=0b01001111;      //display 3 in 7-seg
      break;
    case 4 : 
      Pim.pth.byte=0b01100110;      //display 4 in 7-seg
      break;
    case 5 : 
      Pim.pth.byte=0b01101101;      //display 5 in 7-seg
      break;
    case 6 : 
      Pim.pth.byte=0b01111101;      //display 6 in 7-seg
      break;
    case 7 : 
      Pim.pth.byte=0b00100111;      //display 7 in 7-seg
      break;
    case 8 : 
      Pim.pth.byte=0b01111111;      //display 8 in 7-seg
      break;                                        
    case 9 : 
      Pim.pth.byte=0b01101111;      //display 9 in 7-seg
      break;
    case 10 :
      Pim.pth.byte=0b00000000;      //turn off 7-seg
      break;  
    default:
      break;
  }
  return; 
}

Aucun commentaire:

Enregistrer un commentaire