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.

Help pls convert a code from mikroC PRO for 8051 into Keil uVision5

Status
Not open for further replies.

AyanamiR

Newbie
Newbie level 1
Joined
May 19, 2022
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
15
Hi. I need to convert code from mikroC PRO for 8051 to Keil uVision5.
Thanks for the help.

Code:
/*

 * SW:
     mikroC for 8051 v2.2 [URL]http://www.mikroe.com/[/URL]
 * Test configuration:
     - MCU: AT89С51
       Oscillator:  External Clock 12.000 MHz
*/

//
sbit DIG1 at P1_5_bit;
sbit DIG2 at P1_6_bit;
sbit DIG3 at P1_7_bit;

// Software SPI 
sbit SoftSpi_SDI   at P1_1_bit;
sbit SoftSpi_CLK   at P1_0_bit;
sbit SoftSpi_SDO   at P1_3_bit;
sbit SPI_CS        at P1_2_bit;

//

const char TH1_INIT = 0xE8;     
const char TL1_INIT = 0x00;     

unsigned char digit[3], i, k;   
unsigned int Temp, T_ADC;
unsigned char Led_Table[10] = {0b00111111,  // 0
                               0b00000110,  // 1
                               0b01011011,  // 2
                               0b01001111,  // 3
                               0b01100110,  // 4
                               0b01101101,  // 5
                               0b01111101,  // 6
                               0b00000111,  // 7
                               0b01111111,  // 8
                               0b01101111}; // 9
//
//
void Strob (void)
{
   SoftSpi_CLK = 0;
   Delay_us(7);
   SoftSpi_CLK = 1;
   Delay_us(7);
}
//
//
void Read_ADC (void)
{
   T_ADC = 0;
   SPI_CS = 0;                    
   Strob();
   Strob();
   for (i=0; i<13; i++)              
     {
       SoftSpi_CLK = 0;
       Delay_us(5);
       T_ADC = T_ADC << 1;
       if (SoftSpi_SDI) T_ADC = T_ADC | 1;
       SoftSpi_CLK = 1;
       Delay_us(10);
     }
   SoftSpi_CLK = 0;
   SPI_CS = 1;                    
   return;
}
//
//
void Timer1InterruptHandler() org IVT_ADDR_ET1
{
   EA_bit = 0;                 

   TR1_bit = 0;                 
   TH1 = TH1_INIT;              
   TL1 = TL1_INIT;              

   P2 = Led_Table[digit[0]];    
   DIG1 = 0;
   Delay_ms (3);
   DIG1 = 1;

   P2 = Led_Table[digit[1]];    
   DIG2 = 0;
   Delay_ms (3);
   DIG2 = 1;

   P2 = Led_Table[digit[2]];  
   DIG3 = 0;
   Delay_ms (3);
   DIG3 = 1;

   EA_bit = 1;                 
   TR1_bit = 1;                 
}
//
//
void main()
{
  P0 = 0;
  TF1_bit = 0;           
  ET1_bit = 1;         
  EA_bit  = 1;           

  GATE1_bit = 0;          // Clear this flag to enable Timer1 whenever TR1 bit is set.
  C_T1_bit  = 0;          // Set Timer operation: Timer1 counts the divided-down systam clock.
  M11_bit   = 0;          // M11_M01 = 01    =>   Mode 1(16-bit Timer/Counter)
  M01_bit   = 1;

  TR1_bit = 0;            
  TH1 = TH1_INIT;         
  TL1 = TL1_INIT;        
  TR1_bit = 1;           

  P2 = 255;
  Soft_SPI_Init();        

  digit[0] = 0;          
  digit[1] = 0;       
  digit[2] = 0;          
  do
   {
     TR1_bit = 0;                 
     Read_ADC();                 
     TR1_bit = 1;                 

     Temp  = T_ADC * 9;        
     Temp = Temp / 37;           

     digit[0] = (Temp/100) % 10;  
     digit[1] = (Temp/10) % 10;  
     digit[2] = Temp % 10;        
     Delay_ms(1000);              
   }
  while (1);              
}
[moderator action: corrected formatting tags]
 
Last edited by a moderator:

Hi,

Please give more information what you need.

If you just want other people do the whole job for you we should move this post into the [job offer] section.

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top