0-99 displayed in seven segment display in specified time interval

Thread Starter

jey11

Joined Jun 7, 2010
25
I am using ARM V7 simulator and display 0 to 99 in seven segment display in defined interval. I able to get partially working. Can yo help to fix this?
Thanks
Jey

C:
//#include "address_map_arm.h"
#define HEX3_HEX0_BASE        0xFF200020
#define TIMER_BASE            0xFF202000
   

volatile int * HEX_ptr = (int *)HEX3_HEX0_BASE;


   
typedef struct _timer
{
    int status;
    int control;
    int low_period;
    int high_period;
    int low_counter;
    int high_counter;
   
}timer;

volatile timer* const port_timer = (timer *)TIMER_BASE;

int main(void) {
   
    int interval =100000000;
    int count=0;
    *HEX_ptr=0;
    port_timer->low_period=interval;
    port_timer->high_period=interval>>16;
    //port_timer->control=6;
 
   while(1)
   {
     
      // if(port_timer->status & 1)
       {
          
          for(int i=0; i<16;i++)
          {
             // *HEX_ptr=DisplayHex(i);
            
              port_timer->status =1;
              *HEX_ptr=DisplayNum(i);
              printf(" i =%d \n",i);
              port_timer->control=6;
              count ++;
          }
      
        
       }
     
   }
 
 
}

void DisplayNum(int value)
{
   int lookUpTable[9];
 
   lookUpTable[0] = 0x06;
   lookUpTable[1] = 0x6;
   lookUpTable[2] = 0x5B;
   lookUpTable[3] = 0x4F;
   lookUpTable[4] = 0x66;
   lookUpTable[5] = 0x6D;
   lookUpTable[6] = 0x7D;
   lookUpTable[7] = 0x7;
   lookUpTable[8] = 0x7F;
   lookUpTable[9] = 0x6F;
   
    if (value <10)
       
    {
    *(HEX_ptr)= lookUpTable[value];
    }
    else
    {   
   *(HEX_ptr+1)= lookUpTable[value];
    }
 
}
Moderators note : used code tags
 
Last edited by a moderator:

MrChips

Joined Oct 2, 2009
30,706
Perhaps you are having difficulty in implementing proper engineering system design.
Before you attempt to write code I would suggest that you take the following two mandatory design steps.

1. Draw a block diagram of all the components in your design. Avoid getting into too much detail.
2. Draw a flow-chart or pseudo-code of what processes are required in the program. Avoid using computer or programming jargon.

Writing code is the last thing you should be doing.
 

Thread Starter

jey11

Joined Jun 7, 2010
25
I am using ARM V7 simulator and display 0 to 99 in seven segment display in defined interval. I able to get partially working. Can yo help to fix this?
Thanks
Jey

C:
//#include "address_map_arm.h"
#define HEX3_HEX0_BASE        0xFF200020
#define TIMER_BASE            0xFF202000
 

volatile int * HEX_ptr = (int *)HEX3_HEX0_BASE;


 
typedef struct _timer
{
    int status;
    int control;
    int low_period;
    int high_period;
    int low_counter;
    int high_counter;
 
}timer;

volatile timer* const port_timer = (timer *)TIMER_BASE;

int main(void) {
 
    int interval =100000000;
    int count=0;
    *HEX_ptr=0;
    port_timer->low_period=interval;
    port_timer->high_period=interval>>16;
    //port_timer->control=6;

   while(1)
   {
   
      // if(port_timer->status & 1)
       {
        
          for(int i=0; i<16;i++)
          {
             // *HEX_ptr=DisplayHex(i);
          
              port_timer->status =1;
              *HEX_ptr=DisplayNum(i);
              printf(" i =%d \n",i);
              port_timer->control=6;
              count ++;
          }
    
      
       }
   
   }


}

void DisplayNum(int value)
{
   int lookUpTable[9];

   lookUpTable[0] = 0x06;
   lookUpTable[1] = 0x6;
   lookUpTable[2] = 0x5B;
   lookUpTable[3] = 0x4F;
   lookUpTable[4] = 0x66;
   lookUpTable[5] = 0x6D;
   lookUpTable[6] = 0x7D;
   lookUpTable[7] = 0x7;
   lookUpTable[8] = 0x7F;
   lookUpTable[9] = 0x6F;
 
    if (value <10)
     
    {
    *(HEX_ptr)= lookUpTable[value];
    }
    else
    { 
   *(HEX_ptr+1)= lookUpTable[value];
    }

}
Moderators note : used code tags
Which part works? What does it do or not do?
Not displaying properly. See attached screen shot.

Thanks
JeyDisplay.png
 

Ian Rogers

Joined Dec 12, 2012
1,136
1618321615759.png

Your table is slightly wrong...

You do not show the "connections" to the LED segments.. If that should be displaying 1 then the simulation is set wrong..
 

Thread Starter

jey11

Joined Jun 7, 2010
25
View attachment 235240

Your table is slightly wrong...

You do not show the "connections" to the LED segments.. If that should be displaying 1 then the simulation is set wrong..

//#include "address_map_arm.h"
#define HEX3_HEX0_BASE 0xFF200020
#define TIMER_BASE 0xFF202000


volatile int * HEX_ptr = (int *)HEX3_HEX0_BASE;



typedef struct _timer
{
int status;
int control;
int low_period;
int high_period;
int low_counter;
int high_counter;

}timer;

volatile timer* const port_timer = (timer *)TIMER_BASE;

int main(void) {

char num[11]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x063f};
int interval =10;
int count=0;
*HEX_ptr=0;
port_timer->low_period=interval;
port_timer->high_period=interval>>16;


while(1)
{
for(int i=0; i<12;i++)
{
if (i<10)
{
port_timer->status =1;
*(HEX_ptr)=num;
printf(" i =%d ",i," number %f \n", *HEX_ptr );
port_timer->control=6;
count ++;
}
}
}

}

Thanks, It is working but only display up to 9 and not able to display second digit. How can I fix this?Display.png
 

Ian Rogers

Joined Dec 12, 2012
1,136
Again... I do not know what the 7 segment display is connected to..

It would appear that the port is defined as *HEX that is being sent to the led display, but the physical connections need to be in place.
The issue there is the simulator, not your code. There will be a way to increment *HEX to the next digit, but I do not know that simulator
 

Thread Starter

jey11

Joined Jun 7, 2010
25
Again... I do not know what the 7 segment display is connected to..

It would appear that the port is defined as *HEX that is being sent to the led display, but the physical connections need to be in place.
The issue there is the simulator, not your code. There will be a way to increment *HEX to the next digit, but I do not know that simulator
Thanks for your time and advise.
 

Thread Starter

jey11

Joined Jun 7, 2010
25
Thanks for your time and advise.

Display is fine and the timer delay not functioning properly with this code.

//#include "address_map_arm.h"
#define HEX3_HEX0_BASE 0xFF200020
#define TIMER_BASE 0xFF202000


volatile int * HEX_ptr = (int *)HEX3_HEX0_BASE;



typedef struct _timer
{
int status;
int control;
int low_period;
int high_period;
int low_counter;
int high_counter;

}timer;

volatile timer* const port_timer = (timer *)TIMER_BASE;

int main(void) {

int num[21]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x063f,
0x0606,0x065b,0x064f,0x0666,0x066d,0x067d,0x0607,0x067f,0x066f,0x5b3f};
int interval =100000000;
int count=0;
*HEX_ptr=0;
port_timer->low_period=interval;
port_timer->high_period=interval>>16;
port_timer-> control = 6 ;

while(1)
{
// for(int i=0; i< 22;i++)
// {
// if ( port_timer -> status & 1 )
{
for(int i=0; i< 22;i++)
{
count ++;
port_timer -> status =1;
*(HEX_ptr)=num;
printf(" i =%d ",i );

}

}
}

}
 

Ian Rogers

Joined Dec 12, 2012
1,136
Now I'm not used to the ARM, but... If all registers are 32bit, I'm hoping that an "int" in your compiler is 32bit as you are mapping the timer struct to the timer registers... If they are 16 bit aligned and not 32... They will not be loaded correctly.. Most compilers have a "types" library... ie. UINT32 etc... I have had a quick look but I don't know which ARM core you are referencing..

Just as an observation.. Why are you using absolute address value in your code when you could use pseudo names ie.. The timer control is defined as TCCRO.. then you don't need to know where it is...
 
Top