Microprocessor Hardware programming basics

vtu mp hardware basics
This post is about Microprocessor Hardware programming basics.
Let’s learn some important concepts which are required for the 12 H/W programs. And functions and some syntax too.
INDEX:
1. Basics
2. Executing a H/W program.
3. The Delay function.
4. Conversion of a character to its 7 segment equivalent.
5. The DISP_CHAR function to display a character in 7 segment display.



Lets begin then.
1.Basic concepts:
Lets look at some basic concepts of Microprocessor Hardware programming.
Let me first tell you about I/O ports which are necessary.
  • Port A (PA=0e800H)
Considered to be the Output port in our MP Hardware programming.
  • Port B (PB=0e801H)
 Considered to be the Input port in our MP Hardware programming, but also can be used as output port (this is a bi-directional port).
  • Port C (PC=0e802H)
Control register port. Used to activate the Hardware interface.
  • Control Word (CW)
If our program accepts any input, it should be assigned to 82H.
Otherwise it is 80H.
Used to activate the Hardware interface. It is stored in AL before Enabling hardware Interface.
  • Activating the Hardware interface.
Before starting the logic of a hardware program, we must first enable and activate the Interface.
This is done as follows,
  1. Move the control word (80H/82H depending on the program) into AL.
  2. Move the Control register port address (PC) into DX.
  3. Activate using OUT DX,AL command
This is necessary before we use the Hardware interface in our program.

      • The IN command
If you want to take an input from a hardware interface, you can use IN command. But before calling IN, you must have the input port address stored in DX register. For example, if you want to take input from port B (0e801h).
Use,
MOV DX,0E801H
IN AL,DX

Input taken will be stored in AL register.


     • The OUT command.
To send an output to hardware interface.
Output port address must be in DX. Value to be displayed must be in AL. Then call OUT.
For example,
MOV DX,0E800H
MOV AL,12
OUT DX,AL

will send 12 to hardware interface output.



2. Executing a H/W problem.

Perform the usual “masm program_name.asm;” and “link program_name.obj;
Next, connect the circuit of the interface you want to run properly.
Now run 
allowio 0xe800 program_name.exe
The first try after connection may not give you the correct output. In that case, close the command prompt and run the prompt again, run the allowio command again, it will work now.


3. The Delay function.

This is a procedure which gives a delay between execution of the code. This is necessary in the cases where certain output has to be displayed on the screen for some time without processing the next codes.
Main logic is simple. Load the registers with any high value and then run a very long loop with that register until the number becomes zero.

[NOTE: you can use ANY DELAY FUNCTION of your choice to introduce a delay in the programs. But make sure you PUSH the registers used for the delay function to stack and POP them back in the reverse order. Otherwise you will lose some program data which is surely going to give you run time errors or wrong output.]

Now lets consider the above given DELAY code.
Registers used are CX and BX.
Push them to stack first. (because they might have been used for some purpose in the main program. You don’t need to mess up with those values during delay procedure.

Load CX with a high value. Say 0FFFFH.
Next load BX with a high value. Say 0FFFFH just after a label. Say B1.
Next, run a inner loop with BX until it becomes 0, Decreasing it each time by 1.
When BX becomes zero, JNZ is false and inner loop will break.
Now LOOP back to B1.(LOOP decreases CX by 1)

Until CX becomes zero, outer loop will run. This long iteration process will bring some delay between the execution.
Finally, don’t forget to put RET statement.
Then comes DELAY ENDP stating the end of the procedure.

That’s it. You can use this delay function in any code where you need to introduce a delay.
If you want a smaller time gap, reduce the initial value of BX and CX.

Next concept,

4. Conversion of a character to its 7 segment equivalent.
Consider you want to convert a character ‘H’ to its seven segment equivalent.
Before that, look at this 7 segment positions first.
7 segment display

Now lets get back to our example. That is H.
For H, if you observe, we will select the segments b,c,e,f,g. Conversion is simple.
First write down the segment values like this.
- selected bits are 0
- Not selected bits are 1.
selected bits

Then arrange it in reverse order.
reverse
Find out the Hexadecimal value of the same.
In my case, it is 10001001=>89H.


As simple as that.

5. The DISP_CHAR function to display a character in 7 segment display.
Assumption:
SI is pointing to the offset of the word which we want to display.
In this program, we display characters using Port B. [PB].

Explanation:
In the above code, we assume that there are 4 characters in the word we want to display.
So, after the label NEXT_CHAR, we have assigned CX with 4.
In your case, you assign it with the number of characters in the word you want to display.

Here, we move the character to be displayed into AL. And set BL  to 8. (to run the inner loop for 8 bits/segments)

Next label is NEXT_BIT.
A character has 8 bits in 7 segment display. So each time we take the left most bit of the character’s 7 segment equivalent value and if it is 0, it means it has to be ‘ON’. We will enable it. Otherwise leave the LED off.
We extract the left most bit of AL (the character to be displayed) using ROL instruction. And display it using OUT instruction. (DX must contain port B address).

We need to enable the segment for that particular bit which we are displaying. It uses AH register. So, now push the value of AX into stack(because AL has the character to be displayed)
Enabling the bit is done like this,
Move Port C( control register) to DX. And ‘00H’ to AL and enable it using OUT DX,AL.
Do the same thing again for AL=11H. Now that bit is enabled.

Pop back the AX value.
Decrease BL (counter) by 1. If BL not equal to zero, jump to NEXT_BIT. When 8 bits are displayed, It means that character is displayed completely. Move to next character by increasing SI (to point to next character) and using LOOP NEXT_CHAR.

Finally, return to the called part of the program using RET.
Then DISP_CHAR ENDP indicating the end of DISP_CHAR procedure.


If I find some more concept important, i will update this part ASAP.
Cheers!

He is a simple passionate tech freak who himself is an engineering student at Canara Engineering college. He likes App Development, Web designing, Blogging, Youtubing, Debugging and also is a CodeGeek!

Sharing is sexy!

Related Articles

10 comments

Write comments
Unknown
AUTHOR
24 May 2016 at 03:07 delete

amazing work bro..Thanks a ton for sharing these.. keep up the good work..regards..

Reply
avatar
Anonymous
AUTHOR
26 May 2016 at 23:24 delete

You're a life saver man ... Thanks a ton

Reply
avatar
Anonymous
AUTHOR
27 May 2016 at 14:38 delete

Thanx buddy!

Reply
avatar
Anonymous
AUTHOR
27 May 2016 at 14:39 delete

My pleasure :)

Reply
avatar
Unknown
AUTHOR
10 April 2017 at 21:29 delete

thank you. it's superb for understanding

Reply
avatar
Anonymous
AUTHOR
16 May 2017 at 14:53 delete

Epic bro .all ur gud wishes will come true

Reply
avatar
Anonymous
AUTHOR
22 May 2017 at 19:49 delete

Dude fabulous...even lecturers doesn't teach these things in col..gud work easy to understand..Finally tanx

Reply
avatar
10 July 2017 at 15:08 delete

Great job Mr. Sandesh. All the best wishes

Reply
avatar
Shravan
AUTHOR
9 January 2018 at 16:39 delete This comment has been removed by a blog administrator.
avatar

Share your views about this article!