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.

[SOLVED] does anyone know how to convert microprocessor to C language?

Status
Not open for further replies.

Ni yanfang

Member level 3
Member level 3
Joined
Jul 30, 2013
Messages
59
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
432
org 100h
ljmp main
org 100h
main: clr p3.6
lcall delay
setb p3.6
sjmp main
delay: mov r2,#offh
D1: djnz r6,d1
ret
end
 

The nearest is probably:
Code:
void main()
{
    while(1)
    {
        p3.6 = 0;
        delay();
        p3.6 = 1;
        delay();
    }
}

void delay()
{
    unsigned char r2 = 0xff;
    while(r2--);
}

but most compilers have their own built-in delay functions which would be better to use because the present one is dependant on clock speed. Also note that there is an error in your assembly code, the 'org 100h' is repeated so the ljump to main (second line) is overwritten.

Brian.
 
Ok Thanks a lot.

- - - Updated - - -

after I trun this CODE. can you tell me how to solve?
MYWORK4.C(10): warning C206: 'delay': missing function-prototype
MYWORK4.C(17): error C231: 'delay': redefinition
MYWORK4.C(20): error C231: 'delay': redefinition
 

after I trun this CODE. can you tell me how to solve?
MYWORK4.C(10): warning C206: 'delay': missing function-prototype
MYWORK4.C(17): error C231: 'delay': redefinition
MYWORK4.C(20): error C231: 'delay': redefinition

Insert a function prototype before main():

Code:
[COLOR="#FF0000"]void delay();[/COLOR]

void main()
{
    while(1)
    {
        p3.6 = 0;
        delay();
        p3.6 = 1;
        delay();
    }
}

void delay()
{
    unsigned char r2 = 0xff;
    while(r2--);
}


BigDog
 
Thanks bigdog. do you know what should i add?
MYWORK4.C(9): error C202: 'p3': undefined identifier
MYWORK4.C(9): error C141: syntax error near '='
MYWORK4.C(11): error C202: 'p3': undefined identifier
MYWORK4.C(11): error C141: syntax error near '='
 

You need to include the appropriate device header file at the beginning of your code.

Generic Example:

Code:
#include <xxxxx.h>

What device (make and manufacture) and compiler/IDE toolset are you utilizing?


BigDog
 

I add already
#include<at89x51.h>

- - - Updated - - -

this is my code, kindly check for me.

Code:
#include<at89x51.h> // include at89x51 . h 
#include<stdio.h> // include stdio . h
#include<stdlib.h> // include stdlib . h
void delay();

void main()
{
    while(1)
    {
        p3^6 = 0;
        delay();
        p3^6= 1;
        delay();
    }
}

void delay()
{
    unsigned char r2 = 0xff;
    while(r2--);
}
 
Last edited by a moderator:

Which compiler/IDE are you utilizing, KEIL?

You can always open the device specific header file within the IDE and examine it for appropriately defined symbols:

Reference: KEIL AT89X51.H
Code:
/*--------------------------------------------------------------------------
AT89X51.H

Header file for the low voltage Flash Atmel AT89C51 and AT89LV51.
Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/

#ifndef __AT89X51_H__
#define __AT89X51_H__

/*------------------------------------------------
Byte Registers
------------------------------------------------*/
sfr P0      = 0x80;
sfr SP      = 0x81;
sfr DPL     = 0x82;
sfr DPH     = 0x83;
sfr PCON    = 0x87;
sfr TCON    = 0x88;
sfr TMOD    = 0x89;
sfr TL0     = 0x8A;
sfr TL1     = 0x8B;
sfr TH0     = 0x8C;
sfr TH1     = 0x8D;
sfr P1      = 0x90;
sfr SCON    = 0x98;
sfr SBUF    = 0x99;
sfr P2      = 0xA0;
sfr IE      = 0xA8;
sfr P3      = 0xB0;
sfr IP      = 0xB8;
sfr PSW     = 0xD0;
sfr ACC     = 0xE0;
sfr B       = 0xF0;

/*------------------------------------------------
P0 Bit Registers
------------------------------------------------*/
sbit P0_0 = 0x80;
sbit P0_1 = 0x81;
sbit P0_2 = 0x82;
sbit P0_3 = 0x83;
sbit P0_4 = 0x84;
sbit P0_5 = 0x85;
sbit P0_6 = 0x86;
sbit P0_7 = 0x87;

/*------------------------------------------------
PCON Bit Values
------------------------------------------------*/
#define IDL_    0x01

#define STOP_   0x02
#define PD_     0x02    /* Alternate definition */

#define GF0_    0x04
#define GF1_    0x08

#define SMOD_   0x80

/*------------------------------------------------
TCON Bit Registers
------------------------------------------------*/
sbit IT0  = 0x88;
sbit IE0  = 0x89;
sbit IT1  = 0x8A;
sbit IE1  = 0x8B;
sbit TR0  = 0x8C;
sbit TF0  = 0x8D;
sbit TR1  = 0x8E;
sbit TF1  = 0x8F;

/*------------------------------------------------
TMOD Bit Values
------------------------------------------------*/
#define T0_M0_   0x01
#define T0_M1_   0x02
#define T0_CT_   0x04
#define T0_GATE_ 0x08
#define T1_M0_   0x10
#define T1_M1_   0x20
#define T1_CT_   0x40
#define T1_GATE_ 0x80

#define T1_MASK_ 0xF0
#define T0_MASK_ 0x0F

/*------------------------------------------------
P1 Bit Registers
------------------------------------------------*/
sbit P1_0 = 0x90;
sbit P1_1 = 0x91;
sbit P1_2 = 0x92;
sbit P1_3 = 0x93;
sbit P1_4 = 0x94;
sbit P1_5 = 0x95;
sbit P1_6 = 0x96;
sbit P1_7 = 0x97;

/*------------------------------------------------
SCON Bit Registers
------------------------------------------------*/
sbit RI   = 0x98;
sbit TI   = 0x99;
sbit RB8  = 0x9A;
sbit TB8  = 0x9B;
sbit REN  = 0x9C;
sbit SM2  = 0x9D;
sbit SM1  = 0x9E;
sbit SM0  = 0x9F;

/*------------------------------------------------
P2 Bit Registers
------------------------------------------------*/
sbit P2_0 = 0xA0;
sbit P2_1 = 0xA1;
sbit P2_2 = 0xA2;
sbit P2_3 = 0xA3;
sbit P2_4 = 0xA4;
sbit P2_5 = 0xA5;
sbit P2_6 = 0xA6;
sbit P2_7 = 0xA7;

/*------------------------------------------------
IE Bit Registers
------------------------------------------------*/
sbit EX0  = 0xA8;       /* 1=Enable External interrupt 0 */
sbit ET0  = 0xA9;       /* 1=Enable Timer 0 interrupt */
sbit EX1  = 0xAA;       /* 1=Enable External interrupt 1 */
sbit ET1  = 0xAB;       /* 1=Enable Timer 1 interrupt */
sbit ES   = 0xAC;       /* 1=Enable Serial port interrupt */
sbit ET2  = 0xAD;       /* 1=Enable Timer 2 interrupt */

sbit EA   = 0xAF;       /* 0=Disable all interrupts */

/*------------------------------------------------
P3 Bit Registers (Mnemonics & Ports)
------------------------------------------------*/
sbit P3_0 = 0xB0;
sbit P3_1 = 0xB1;
sbit P3_2 = 0xB2;
sbit P3_3 = 0xB3;
sbit P3_4 = 0xB4;
sbit P3_5 = 0xB5;
sbit P3_6 = 0xB6;
sbit P3_7 = 0xB7;

sbit RXD  = 0xB0;       /* Serial data input */
sbit TXD  = 0xB1;       /* Serial data output */
sbit INT0 = 0xB2;       /* External interrupt 0 */
sbit INT1 = 0xB3;       /* External interrupt 1 */
sbit T0   = 0xB4;       /* Timer 0 external input */
sbit T1   = 0xB5;       /* Timer 1 external input */
sbit WR   = 0xB6;       /* External data memory write strobe */
sbit RD   = 0xB7;       /* External data memory read strobe */

/*------------------------------------------------
IP Bit Registers
------------------------------------------------*/
sbit PX0  = 0xB8;
sbit PT0  = 0xB9;
sbit PX1  = 0xBA;
sbit PT1  = 0xBB;
sbit PS   = 0xBC;
sbit PT2  = 0xBD;

/*------------------------------------------------
PSW Bit Registers
------------------------------------------------*/
sbit P    = 0xD0;
sbit F1   = 0xD1;
sbit OV   = 0xD2;
sbit RS0  = 0xD3;
sbit RS1  = 0xD4;
sbit F0   = 0xD5;
sbit AC   = 0xD6;
sbit CY   = 0xD7;

/*------------------------------------------------
Interrupt Vectors:
Interrupt Address = (Number * 8) + 3
------------------------------------------------*/
#define IE0_VECTOR	0  /* 0x03 External Interrupt 0 */
#define TF0_VECTOR	1  /* 0x0B Timer 0 */
#define IE1_VECTOR	2  /* 0x13 External Interrupt 1 */
#define TF1_VECTOR	3  /* 0x1B Timer 1 */
#define SIO_VECTOR	4  /* 0x23 Serial port */

#endif





Be aware originally your code referenced P3.6:

Code:
void delay();

void main()
{
    while(1)
    {
        [COLOR="#FF0000"]p3.6[/COLOR] = 0;
        delay();
       [COLOR="#FF0000"] p3.6[/COLOR] = 1;
        delay();
    }
}

void delay()
{
    unsigned char r2 = 0xff;
    while(r2--);
}

While your latest version references p3^6

Code:
#include<at89x51.h> // include at89x51 . h 
#include<stdio.h> // include stdio . h
#include<stdlib.h> // include stdlib . h
void delay();

void main()
{
    while(1)
    {
        [COLOR="#FF0000"]p3^6[/COLOR] = 0;
        delay();
        [COLOR="#FF0000"]p3^6[/COLOR]= 1;
        delay();
    }
}

void delay()
{
    unsigned char r2 = 0xff;
    while(r2--);
}

While the KEIL AT89x51.H header file defines the following for PORT3 PIN7:
Code:
...

/*------------------------------------------------
P3 Bit Registers (Mnemonics & Ports)
------------------------------------------------*/
sbit P3_0 = 0xB0;
sbit P3_1 = 0xB1;
sbit P3_2 = 0xB2;
sbit P3_3 = 0xB3;
sbit P3_4 = 0xB4;
sbit P3_5 = 0xB5;
[COLOR="#FF0000"]sbit P3_6 = 0xB6;[/COLOR]
sbit P3_7 = 0xB7;

...

Also be aware pin number usually begins with the number '0' not '1'.

BigDog
 
i am using keil to run this program.

Alright, try using the following code:

Code:
#include<at89x51.h> // include at89x51 . h 
#include<stdio.h> // include stdio . h
#include<stdlib.h> // include stdlib . h
void delay();

void main()
{
    while(1)
    {
        [COLOR="#FF0000"]p3_6[/COLOR] = 0;
        delay();
        [COLOR="#FF0000"]p3_6[/COLOR]= 1;
        delay();
    }
}

void delay()
{
    unsigned char r2 = 0xff;
    while(r2--);
}

Ensure the LED is attached to the 7th pin of PORT3.

BigDog
 

.... through a series resistor !

And unless you are using a very slow clock speed, don't expect it to flash visibly, the present delay is very short (probably a few mS) which is why I suggested looking for delay routines built into the compiler libraries.

Brian.
 

Yes. connection is correct. but still can not.Kindly check for me.
MYWORK4.C(10): error C202: 'p3_6': undefined identifier
MYWORK4.C(12): error C202: 'p3_6': undefined identifier
 

The instructions to make the pin high and low are "p3_6 = 1" and "p3_6 = 0" so what the message is telling you is the names of the pins are not recognized. You are missing the link between the name "p3_6" and the actual hardware. This is usually in the header file (.h file) for the processor. Check the name matches the pin definition and that you have it in the correct case (for example 'p' when it should be 'P').

Brian.
 
The instructions to make the pin high and low are "p3_6 = 1" and "p3_6 = 0" so what the message is telling you is the names of the pins are not recognized. You are missing the link between the name "p3_6" and the actual hardware. This is usually in the header file (.h file) for the processor. Check the name matches the pin definition and that you have it in the correct case (for example 'p' when it should be 'P').

Brian.
Thanks brain. You are right.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top