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.

P89V51RD2 Microcontrollers

Status
Not open for further replies.

angiey

Junior Member level 1
Junior Member level 1
Joined
Jul 2, 2012
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,436
Hi all,
Can anybody tell me how to assign values to the individual ports,[0to15 hex decimal values to ports] i mean to say i have taken port2 as my reference
in this i have to assign P2.0=0 ; P2.2 = 0 ; P2.4=0 ; P2.6=1; this is first set value i.e.,0001 means it should display 7v,
similarly 0010 it should display as (eg..9v),in hardware already made the changes and build a seperate circuit for R2R ladder.
Kindly give me an idea to solve this problem using c programming lang.
Thanks in advance.
 

u can simply define each pin in keil by
Code:
sbit d1=P2^0;
sbit d2=P2^2;
sbit d3=P2^4;
sbit d4=P2^6;
 

Thanks...i have already defined in this way...but after this assigning voltages to each port and testing it,may be in this method i'm going wrong...
 

I could not post my complete code here...hope this might help me..
I tried to attach the file but getting invalid file name...below is the main.c code....i have left the comment lines as it is...[since i had tried but didn't worked]
void fnSelectVoltage(void)
{
//int V1,V2,V3,V4;
//V1 = 7;
//V2 = 9;
//V3 = 11;
//V4 = 12;

line_display(1, "Volt Sel");
sprintf(line_buf," %d V",(unsigned int)voltagedesired); // " %03d V"
line_display(2, line_buf);

while(START_KEY)
{
if(!UP_KEY)
{
wait_for_any_key_counter_0 = 0;
// voltagedesired++;
// if(voltagedesired >= Max_vg_selected)
// voltagedesired = Min_vg_selected;

if(V1 == 1 || V2 == 1 || V3 == 1 || V4 == 0) //this i have checked for and(&&) operation also
{
V1 = 1; //V1=7; V1 = voltagedesired++;
}
else

if(V1 == 1 || V2 == 1 || V3 == 0 || V4 == 1)
{
V4 = 1; //V1=9; V4 = voltagedesired++;
}
// else
//

}
else if(!DOWN_KEY)
{
wait_for_any_key_counter_0 = 0;
// voltagedesired--;
// if(voltagedesired <= Min_vg_selected)
// voltagedesired = Max_vg_selected;


if(V1 == 1 || V2 == 1 || V3 == 1 || V4 == 0)
{
V1 = 0; //V1=7; V1 = voltagedesired--;
}
else

if(V1 == 1 || V2 == 1 || V3 == 0 || V4 == 1)
{
V4 = 1; //V1=7; V4 = voltagedesired--;
}
// else
//

/////////////////////////////////////////////////////////////////////////main.h file
//voltage declarations
sbit V1 = P2^0;
sbit V2 = P2^2;
sbit V3 = P2^4;
sbit V4 = P2^6;

//voltage declaration
#define Initial_vg_selected 7
#define Min_vg_selected 5
#define Max_vg_selected 12
void fnSelectVoltage(void);
void delay_ms(unsigned int j);

thanks in advance...

- - - Updated - - -

I could not post my complete code here...hope this might help me..
I tried to attach the file but getting invalid file name...below is the main.c code....i have left the comment lines as it is...[since i had tried but didn't worked]
void fnSelectVoltage(void)
{
//int V1,V2,V3,V4;
//V1 = 7;
//V2 = 9;
//V3 = 11;
//V4 = 12;

line_display(1, "Volt Sel");
sprintf(line_buf," %d V",(unsigned int)voltagedesired); // " %03d V"
line_display(2, line_buf);

while(START_KEY)
{
if(!UP_KEY)
{
wait_for_any_key_counter_0 = 0;
// voltagedesired++;
// if(voltagedesired >= Max_vg_selected)
// voltagedesired = Min_vg_selected;

if(V1 == 1 || V2 == 1 || V3 == 1 || V4 == 0) //this i have checked for and(&&) operation also
{
V1 = 1; //V1=7; V1 = voltagedesired++;
}
else

if(V1 == 1 || V2 == 1 || V3 == 0 || V4 == 1)
{
V4 = 1; //V1=9; V4 = voltagedesired++;
}
// else
//

}
else if(!DOWN_KEY)
{
wait_for_any_key_counter_0 = 0;
// voltagedesired--;
// if(voltagedesired <= Min_vg_selected)
// voltagedesired = Max_vg_selected;


if(V1 == 1 || V2 == 1 || V3 == 1 || V4 == 0)
{
V1 = 0; //V1=7; V1 = voltagedesired--;
}
else

if(V1 == 1 || V2 == 1 || V3 == 0 || V4 == 1)
{
V4 = 1; //V1=7; V4 = voltagedesired--;
}
// else
//

/////////////////////////////////////////////////////////////////////////main.h file
//voltage declarations
sbit V1 = P2^0;
sbit V2 = P2^2;
sbit V3 = P2^4;
sbit V4 = P2^6;

//voltage declaration
#define Initial_vg_selected 7
#define Min_vg_selected 5
#define Max_vg_selected 12
void fnSelectVoltage(void);
void delay_ms(unsigned int j);

thanks in advance...
 

What is your actual problem? Explain in detail.

Hi,
I'm working on 89v51 microcontroller, the thing is i have to initialize four ports[say P2.0,P2.1,P2.2,P2.3] and assign binary values 0000 TO 1111 to each port[i.e hex no's from 0 to F]say P2.0=0;P2.1=0;P2.2=0;P2.2=1 and it goes on till last binary value, and there are two keys for the operation up & down key,when up key is pressed it should set 0010 and display 7v and viceversa for down key operation[this is for eg]since for the hardware part i have used R2R ladder for the voltage conversion, but the thing is this should be generated by micro controller.Kindly give me an idea to resolve this.

Hexadecimal Binary Voltages

0 0000 5v
1 0001 6v
2 0010 7v
3 0011 8v
4 0100 9v
5 0101 10v
6 0110 10.1v
7 0111 10.2v
8 1000 it goes on till 14v
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111 14v
 

please clearly explain the problem statement. !! and P2.0.. p2.1 are the port pins, not port .!!
 

You using R2R ladder for P2.0 to P2.3? i.e., 4 bit digital to Analog conversion? Or do you want to convert 8 bits? You have to use P2 = 0x00 which will make P2 as output. Then you can write any value to it. If you want to write 1111 to P2.0 to P2.3 then you have to use P2 = 0x0F; Create a table of 16 binary values that you want to use. and use a pointer to these values and dereference the pointer and assign the values one by one to P2.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
unsigned char DAC_table[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
unsigned char *ptr2tbl = &DAC_table;
 
 
for(i = 0; i <15; i++){
 
          P2 = *ptr2tbl++;
          delay_ms(1000);
         
}

 
Last edited:
  • Like
Reactions: angiey

    angiey

    Points: 2
    Helpful Answer Positive Rating
You using R2R ladder for P2.0 to P2.3? i.e., 4 bit digital to Analog conversion?


I just tried what you told but i'm getting error near DAC_table as syntax error,although i checked it by assigning int and char...and particular version of the language standard is not supported by the compiler?please help me out in resolving this


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
unsigned char DAC_table[16];      
unsigned char *ptr2tbl; 
void fnSelectVoltage(void)
{
 
line_display(1, "Volt Sel");
    sprintf(line_buf," %d V",(unsigned int)*ptr2tbl);       
    line_display(2, line_buf);
 
 DAC_table[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};//at this line i'm finding syntax error '{'}'
*ptr2tbl = &DAC_table;  
    while(START_KEY)
    {
        if(!UP_KEY)
        {   
            wait_for_any_key_counter_0 = 0;
 
            for(i = 0; i <15; i++)      
            {
              P2 = *ptr2tbl++;
            //  delay_ms(1000);         
         
            }
        }
        else if(!DOWN_KEY)
        {
            wait_for_any_key_counter_0 = 0;
 
          for(i = 0; i <15; i++)        
            {
          P2 = *ptr2tbl--;
         // delay_ms(1000);             
         
            }
        }

[/QUOTE]
 


Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top