0% found this document useful (0 votes)
12 views

Lab # 3

This document describes an embedded systems lab experiment on converting between packed binary-coded decimal (BCD) and ASCII codes using a PIC16F877A microcontroller. The lab objectives are to interconvert packed BCD and ASCII code. The apparatus used includes a PIC16F877A microcontroller, resistors, LEDs, and a bar graph. Software tools like MPLABX IDE, XC8 compiler, and Proteus are used. The document explains the theory behind embedded systems, packed and unpacked BCD, and ASCII. It then describes the code implemented on the PIC to convert between packed BCD and its ASCII character equivalent. Successful results are shown in Proteus and conclusions are drawn about learning

Uploaded by

inzamam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Lab # 3

This document describes an embedded systems lab experiment on converting between packed binary-coded decimal (BCD) and ASCII codes using a PIC16F877A microcontroller. The lab objectives are to interconvert packed BCD and ASCII code. The apparatus used includes a PIC16F877A microcontroller, resistors, LEDs, and a bar graph. Software tools like MPLABX IDE, XC8 compiler, and Proteus are used. The document explains the theory behind embedded systems, packed and unpacked BCD, and ASCII. It then describes the code implemented on the PIC to convert between packed BCD and its ASCII character equivalent. Successful results are shown in Proteus and conclusions are drawn about learning

Uploaded by

inzamam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Embedded Systems Lab # 3 MTE-409

 Objective:
Inter-convert packed BCD to ASCII code using PIC 16F877A

 Apparatus:
i. PIC 16F877A
ii. Resistor(1Kohm)
iii. LEDs
iv. Bar Graph.

 Softwares:
i. MPLABX IDE
ii. XC8 compiler
iii. Proteus.

 Theory:
1) Embedded System:
A system based on microcontroller/microprocessor or an FPGA which is not a computer itself but whose
sole purpose is computational. E.g. Modern Photo Copier Machine, Printer, Cell Phones etc. Embedded
electronics is all about interlinking circuits (processors or other integrated circuits) to create a symbiotic
system.
In order for those individual circuits to swap their information, they must share a common communication
protocol. Hundreds of communication protocols have been defined to achieve this data exchange, and, in
general, each can be separated into one of two categories: parallel or serial.
2) Packed BCD and Unpacked BCD:
In computing and electronic systems, binary-coded decimal (BCD) is a class of binary encodings of decimal
numbers where each decimal digit is represented by a fixed number of bits. Packed BCD is the first and
second number are represented as the first 4 bits and last 4 bits in a byte. The number 75 in packed BCD
would be 01110101. Unpacked BCD is each number is represented by its own byte. The number 75 in
unpacked BCD would be 00000111 and 00000101.
3) ASCII:
ASCII abbreviated from American Standard Code for Information Interchange, is a character encoding
standard for electronic communication. ASCII codes represent text in computers, telecommunications
equipment, and other devices. Most modern character-encoding schemes are based on ASCII, although they
support many additional characters.
4) Packed BCD to ASCII:
BCD uses only the digits 0 to 9. An unpacked BCD digit uses the lower nibble of an entire byte and to
convert it to ASCII.

Packed BCD Unpacked BCD ASCII Code


0x29 0x09,0x20 0x32,0x39

Attique Ur Rehman (17-003) Page # 1


Embedded Systems Lab # 3 MTE-409
5) Code:

/*********************************Header Files******************************/
#define _XTAL_FREQ 20000000
#include <xc.h>
__PROG_CONFIG (1,0X3F32);
/***************************************************************************/

/****************************Function Declaration***************************/
void BCD_TO_ACSII(void);
void ASCII_TO_BCD(void);
/***************************************************************************/

/*********************************Main Program******************************/
void main(void)
{
//Converting Binary Coded Decimals into ASCII
BCD_TO_ASCII();
//Wait for two minutes
__delay_ms(2000);
//Converting ASCII to Binary Coded Decimals
ASCII_TO_BCD();
while(1);
return;
}
/***************************************************************************/

/*********************************Function Definition************************/
void BCD_TO_ASCII()
{
TRISB = 0x00;
TRISD = 0x00;
//Convert packed BCD into ASCII 0x32 and 0x39
unsigned char a, b;
unsigned char temp = 0x29;
// Converting into 0x39
a = (temp & 0x0F) | 0x30;
b = (temp >> 4) | 0x30;

Attique Ur Rehman (17-003) Page # 2


Embedded Systems Lab # 3 MTE-409

PORTB = a;
PORTD = b;
}
/***************************************************************************/
void ASCII_TO_BCD()
{
TRISB = 0x00;
//Convert ASCII into packed BCD
unsigned char a = 0x39, b = 0x32;
//Converting into 0x09
a = a & 0x0F;
//Converting into 0x20
b = b << 4;
//Converting into 0x29
a = a | b;
PORTB = a;
}
/***************************************************************************/
6) Software Implementation:

Attique Ur Rehman (17-003) Page # 3


Embedded Systems Lab # 3 MTE-409

7) Successful building and uploading:

Attique Ur Rehman (17-003) Page # 4


Embedded Systems Lab # 3 MTE-409
8) Results:

Packed BCD to ASCII

ASCII to packed BCD

 Procedure:
i. First, I converted the packed BCD (0x29) into ASCII code (0x32,0x39).
ii. Then I declared the variables for ASCII and for packed BCD.
iii. Also I initialize the temp variable with 0x29.
iv. Then I applied the masked gate with 0x0F to convert the 0x29 into 0x09 and OR with 0x30 for
convert the 0x09 into 0x39 and stored this ASCII into the variable ‘i’.
v. Again, use the temp variable with four times right shift for convert the 0x29 into 0x02 and OR with
0x30 to convert 0x02 into 0x32 and stored this ASCII into the variable ‘j’.
vi. Then I sent the data of variables ‘i’ and ‘j’ on PORTB an PORTD of PIC16F877A.
vii. Then I Connected the LED BARGRAPH with these ports for indication of bits.
viii. Then I verified the logic in Proteus that I implemented in program.

Attique Ur Rehman (17-003) Page # 5


Embedded Systems Lab # 3 MTE-409
ix. After that in second part, I convert this ASCII (0x32,0x39) into packed BCD(0x29).
x. I initialized the two variables (a = 0x39 and b = 0x32).
xi. Then I applied the masked gate on ‘a’ with 0x0F and four times left shift the ‘b’ variable.
xii. After that I performed OR operation between variables a and b.
xiii. Then I verified the logic in proteus that I implemented in program.

 Conclusion:
In this lab, I have explored, learned and implemented conversion of BCD to ASCII and vice versa by using
PIC16F877A microcontroller.

Attique Ur Rehman (17-003) Page # 6

You might also like