Need Urgent help ! , C++ code to Initialize ports on 8051 microcon
I am a complete newbie to the site and to the world of microcontrollers, although I have taken assembly language class during college.
I need some help immediately with initializing ports on a 8051 microcontroller.
I am working at this electronics engineering company as a operations manger and I would like to step up to becoming an engineer ( that's what i graduated in ) - But unfortunately due to financial and other reasons I had to take this job , at this engineering company and have to work my way up . .
My boss just gave me an assignment to "Initialize the ports on the 8051 microcontroller , using C++" AND I told him I can do it, but I have no idea how to do it .
Can you help me please??
I have the data sheet and everything ( PDF)
Someone already helped me with few lines of the code ..
P0 = 0x0F ; write to port
var = P0 ; reads the port into a char variable
Pin0 = 1 ; set port 0 pin 0 bit to 1
bit = Pin0 ; reads port 0 pin 0 into bit
P0MDIN = 0xFF ; setting to 1's
P0MDOUT = 0xFF ; push pull
P0SKIP = 0xFF ; setting port 0 to skip
XBR1 |= 0X40 ; setting xbare bit in XBR1 register
I looked at the data sheet and it seemed to make sense to me..But could you help me finish it please? I am trying to move up within in the company..
There are 3 ports in total -( p0, p1, p2 )
I need some help immediately with initializing ports on a 8051 microcontroller.
I am working at this electronics engineering company as a operations manger and I would like to step up to becoming an engineer ( that's what i graduated in ) - But unfortunately due to financial and other reasons I had to take this job , at this engineering company and have to work my way up . .
My boss just gave me an assignment to "Initialize the ports on the 8051 microcontroller , using C++" AND I told him I can do it, but I have no idea how to do it .
Can you help me please??
I have the data sheet and everything ( PDF)
Someone already helped me with few lines of the code ..
P0 = 0x0F ; write to port
var = P0 ; reads the port into a char variable
Pin0 = 1 ; set port 0 pin 0 bit to 1
bit = Pin0 ; reads port 0 pin 0 into bit
P0MDIN = 0xFF ; setting to 1's
P0MDOUT = 0xFF ; push pull
P0SKIP = 0xFF ; setting port 0 to skip
XBR1 |= 0X40 ; setting xbare bit in XBR1 register
I looked at the data sheet and it seemed to make sense to me..But could you help me finish it please? I am trying to move up within in the company..
There are 3 ports in total -( p0, p1, p2 )
Replies
-
Harshad ItaliyaWhat is the Requirement of your Ports means in input mode output mode or QB mode??
-
Harshad ItaliyaDear By Default all ports are in INPUT mode
Write...
If you want just initialization then this is enough...
P0 = 0x00; // Port 0 in input mode
P0 = 0xFF; // Port 0 in Output mode..
if you want to Toggle LED at Specific pin than
led = P0^1; //Port 0 pin1 assign as led
now according to led variable LED will toggle.
Can please tell me where is the problem i think your initialization is Ok !! -
JAIHOHere's the schematics of "what the company will use this chip for " .
I just scanned and resized it.I am not sure if I need input ports or output ports or QB...??
#-Link-Snipped-#
The initialization is ok ? But the code I have only looks like it's dealing with Port0 Only !!
How do I Initialize Port1 ( 8 pins ) and Port 2 ( 2 pins ) , with regards to the design requirements ?? -
Harshad ItaliyaYou can initialize all port by same manner..
P1= 0x00; input only
P2= 0x00; input only
and yes if you want to initialize only one or two pin then set them to one and remaining pins should set to zero..
Which controller you are using? -
JAIHOThe controller , I think , we will be using , is a C8051F330 GM
PDF ( page 120 )
So is this all I need to do to initialize the ports?
P0= 0x00; input
P1= 0x00; input
P2= 0x00; input
Are all the ports are supposed to be Input or some Output and some Input ? ? and also , do I need to toggle an LED or not?
Where can I get this information from? I was looking at the schematics and it looks like there are arrows going- in as well as arrows going- out? -
Harshad ItaliyaAs per your Circuit Diagram i conclude that...
Port 0 is in QB which is in QB by Default so no need to Initialize it
Port 1 is also in QB cause there is SPI communicate with Controller
Port 2 as Output.
i can give you value but before that i have to understood the circuit working -
Harshad ItaliyaDear JAIHO,
i had just gone through your C8051F33 datasheet..
as per the description given on the page 121 we have to set
P0MDIN P0MDOUT P0SKIP ---- For Port 0
and same for all port.... for the value which we will load in That SFR i have to Understood the Working of your Circuit then and then i can give you that valur so it is better that you please first understood the circuit that what is the Function of each pin by that manner you are aware with the possible state of that pin and form that set the SFR i had written above for all port..
Hop this will helps you.. -
JAIHOok, You are a very helpful person. I am sure everyone here feel the same way. By the way, do you mean Serial peripheral interface by SPI, and what does Qb stands for?
-
Harshad ItaliyaQB is Quasi Bidirectional in this mode Post configured as input as well as output.
PS:- We are Crazyengineers Cheers JAIHO.
Hop you will get your Solution please try to Run and debug this will also helps you. 😉 -
JAIHOwait - haha , so is this what you think I need to understand first and also I should understand the possible state of the following pins??
p0.1 - Pwr div
p0.6 - Pwr En (enable)
p0.4 - Ext_ voltage
p0.3 - Motion
p0.2 - Btn_1
p0.5 - In Ignition
p0.7 - SPI SCK
p1.0 - SPI MISO
p1.1 - SPI MISO
p1.2 - SPI SEL
p1.3 - 12C SDA
p1.4 - 12C SCL
p1.6 - LED 1
p1.7 - VBATT/2
p1.5 - 2.8V IO_Enable
p2.0 - C2D
RST/C2CK
VDD ( +2.8 Volts )
GND
Can you tell me details on what is it that I need to understand about these pins?
for example :- One of the things i need to understand is , if it is a push pull pin right? -
Harshad ItaliyaYes thats what i am asking.. get the possibilities and according to them configure the Port suppose you had connected LED at P1.6 so configure it as Output only.. so on..
-
JAIHODo you know what a "Crossbar" is ? Is that where all the connections come into ? Why do we need to set it ?
Also my understanding of a push pull pin is that , when it's Digital "1" it's active high and the line is pulled down . meaning anything that's functioning is stopped for a little while.
When it's Digital "0" , it's active low and the line is pulled down , meaning everything is back to functioning normally?
Am i correct in my understanding?
You are reading an archived discussion.
Related Posts
Hi friends,
I am in 2nd year of engineering (CSE) .I would like to buy a laptop
before the next sem starts.I don't have any idea about laptops
I am...
Dear Members
Im working in GAS Plant as a QC INSTRUMENTATION INSPECTOR, I want to learn FEED and change my career as Instrumentation Engineer, Pls provide me the best resources...
Facebook is losing its CFO Gideon Yu. The Wall Street Journal broke the news earlier today, and speculated that the reason could be that Facebook might want to make an...
CEans,
As engineers, we are responsible for the well being of the world. When it comes to the well being of the on-line world; we all rely on software that...
Hi guys,
I've been searching the net for guides and components needed to create a closed circuit taser. Is that the right term for it? Hopefully i found the right...