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

RTES Lab Programs

Uploaded by

jaygangula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

RTES Lab Programs

Uploaded by

jaygangula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

To blink LEDs which are controlled by the 89C51 C by displaying the results and observe the
controlling characteristics
a) LED interfacing Source mode
#include <reg51.h>
void main(void)
{
unsigned int i;
for(i=0;i<5000;i++);
for(i=0;i<5000;i++);
P1=0x01;
}
b) LED interfacing Sink mode
#include <reg51.h>
void main(void)
{
unsigned int i;
for(i=0;i<5000;i++);
for(i=0;i<5000;i++);
P1=0xfe;
}
c) Embedded C program to toggle P1.0 continuously
#include<reg51.h>
sbit mybit= P1^0;
void main(void)
{
unsigned int i;
while(1)
{
for(i=0;i<2000;i++);
mybit=0;
for(i=0;i<2000;i++);
mybit=1;
}
}
2. To study the different switching aspects and analyse the switch control mechanism implemented
through 89C51 C: Switch and LED interfacing
#include <reg51.h>
sbit LED = P2^4;
sbit SW=P2^2;
void Delay(const unsigned int x) //Function to provide delay
{
unsigned int L1=0;
unsigned int L2=0;
for(; L1 < x; L1++)
{
for(L2=0; L2 <6553; L2++)
{}
}
}
int main()
{
SW=1;
LED=0; //configuring as output pin
while(1)
{
if((SW ==0))
{
LED=1; //Make pin high
Delay(1);
}
else
{
LED=0; // Make pin low
Delay(1);
}
}
}
3. To study the serial communication capabilities of a microcontroller and analyze for different aspects
using a program on 89c51 C
a) Serial data transmission
MOV TMOD,#20H ;timer 1,mode 2(auto reload)
MOV TH1,#-6 ;4800 baud rate
MOV SCON,#50H ;8-bit, 1 stop, REN enabled
SETB TR1 ;start timer 1
AGAIN:MOV SBUF,#"A" ;letter "A" to transfer
HERE: JNB TI, HERE ;wait for the last bit
CLR TI ;clear TI for next char
SJMP AGAIN ;keep sending A
end
b) Serial data reception
org 0000h
MOV TMOD,#20H ;timer 1,mode 2(auto reload)
MOV TH1,#-6 ;4800 baud rate
MOV SCON,#50H ;8-bit, 1 stop, REN enabled
SETB TR1 ;start timer 1
HERE: JNB RI,HERE ;wait for the last bit
MOV A,SBUF
MOV P1,A
CLR RI ;clear RI for next char
SJMP HERE ;keep sending A
END

4. To activate & control the seven-segment display unit with 89C51 C: Program to display 0-9
continuously
include <reg51.h>
#define DATA P2
void delay(unsigned int );
int main()
{
while(1)
{
DATA=0xc0;
delay(500);
DATA=0xf9;
delay(500);
DATA=0xa4;
delay(500);
DATA=0xb0;
delay(500);
DATA=0x99;
delay(500);
DATA=0x92;
delay(500);
DATA=0x82;
delay(500);
DATA=0xf8;
delay(500);
DATA=0x80;
delay(500);
DATA=0x90;
delay(500);
}

}
void delay(unsigned int t) //delay t*25msec
{
unsigned int i,j;
for(i=0; i<t; i++)
for(j=0; j<1275; j++);
}
5. To examine the liquid crystal display (LCD) control characteristics on 89C51 C using the
appropriate program modes Sensor interfacing
#include <reg51.h>
sfr ldata = 0x0a0; //P2=LCD data pins
sbit rs = P3^7;
sbit rw = P3^6;
sbit en = P3^5;
unsigned char str1 [16]="VardhamanCollege";
unsigned char str2 [15]=" of Engineering";
void MSDelay (unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
void lcdcmd(unsigned int value)
{
ldata = value; //put the value on the pins
rs = 0;
rw = 0;
en = 1; //strobe the enable pin
MSDelay(1);
en = 0;
return;
}
void lcddata(unsigned char value)
{
ldata = value ; //put the value on the pins
rs = 1;
rw = 0;
en = 1; //strobe the enable pin
MSDelay(5);
en = 0;
return;
}
void main()
{
unsigned int x;
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x80); //line 1, position 6
for(x=0;x<16;x++)
{
lcddata (str1[x]);
MSDelay(25);
}
lcdcmd(0xc0);
for(x=0;x<15;x++)
{
lcddata (str2[x]);
MSDelay(25);
}
while(1);
}
6. To study the sensor control characteristics and different sensing capabilities of a sensor
implemented by the program via the 89C51 C
a) IR Interfacing with 8051(Obstacle Detection)
#include <reg51.h>
#include <stdio.h>
sfr ldata = 0x0A0;
sbit rs = P3^7;
sbit rw = P3^6;
sbit en = P3^5;
sbit IR=P1^0;// Connect the data pin of IR to pin N0 13
void Delay(unsigned int time);
void LCD_Init(void);
void LCD_Cmd(unsigned char cmd);
void LCD_Data(unsigned char dat);
void LCD_Print(char *str);
void main() {
LCD_Init();
LCD_Print(" IR Interfacing");
while(1) {
if(IR == 0) {
LCD_Cmd(0xc0);
LCD_Print("ObstacleDetected");
Delay(1);
} else {
LCD_Cmd(0xc0);
LCD_Print(" No Obstacle ");
}
}
}
void LCD_Init(void) {
LCD_Cmd(0x38);
LCD_Cmd(0x0E);
LCD_Cmd(0x01);
LCD_Cmd(0x06);
LCD_Cmd(0x80);
}

void LCD_Cmd(unsigned char cmd) {


ldata = cmd;
rs = 0;
rw = 0;
en = 1;
Delay(1);
en = 0;
}
void LCD_Data(unsigned char dat) {
ldata = dat;
rs = 1;
rw = 0;
en = 1;
Delay(1);
en = 0;
}
void LCD_Print(char *str) {
while (*str) {
LCD_Data(*str++);
}
}
void Delay(unsigned int time) {
unsigned int i, j;
for (i = 0; i < time; i++)
for (j = 0; j < 1275; j++);
}
b) LDR Interfacing with 8051
#include <reg51.h>
#include <stdio.h>
sfr ldata = 0x0A0;
sbit rs = P3^7;
sbit rw = P3^6;
sbit en = P3^5;
sbit LDR = P1^0;// Connect the data pin of LDR to pin N0 13
void Delay(unsigned int time);
void LCD_Init(void);
void LCD_Cmd(unsigned char cmd);
void LCD_Data(unsigned char dat);
void LCD_Print(char *str);
void main() {
LCD_Init();
LCD_Print("LDR Interfacing");
while(1) {
if(LDR == 1) {
LCD_Cmd(0xc0);
LCD_Print(" LOW Brightness ");
Delay(1);
} else {
LCD_Cmd(0xc0);
LCD_Print(" HIGH Brightness ");
}
}
}
void LCD_Init(void) {
LCD_Cmd(0x38);
LCD_Cmd(0x0E);
LCD_Cmd(0x01);
LCD_Cmd(0x06);
LCD_Cmd(0x80);
}
void LCD_Cmd(unsigned char cmd) {
ldata = cmd;
rs = 0;
rw = 0;
en = 1;
Delay(1);
en = 0;
}
void LCD_Data(unsigned char dat) {
ldata = dat;
rs = 1;
rw = 0;
en = 1;
Delay(1);
en = 0;
}

void LCD_Print(char *str) {


while (*str) {
LCD_Data(*str++);
}
}
void Delay(unsigned int time) {
unsigned int i, j;
for (i = 0; i < time; i++)
for (j = 0; j < 1275; j++);
}
7. To demonstrate the LED Blinking and Seven Segment Display Using ARM Processor
a) LED blinking on STM32(ARM Cortex M4 processor)

void setup() {
pinMode(D2, OUTPUT);
}
void loop() {
digitalWrite(D2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(D2, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
b) 7segmetn display interfacing with stm32(ARM Cortex M4 processor)
const int segmentPins[] = {D2, D3, D4, D5, D6, D7, D8}; // A, B, C, D, E, F, G
// Segment configuration for each digit (LOW = ON, HIGH = OFF)
const int digits[10][7] = {
{0, 0, 0, 0, 0, 0, 1}, // 0
{1, 0, 0, 1, 1, 1, 1}, // 1
{0, 0, 1, 0, 0, 1, 0}, // 2
{0, 0, 0, 0, 1, 1, 0}, // 3
{1, 0, 0, 1, 1, 0, 0}, // 4
{0, 1, 0, 0, 1, 0, 0}, // 5
{0, 1, 0, 0, 0, 0, 0}, // 6
{0, 0, 0, 1, 1, 1, 1}, // 7
{0, 0, 0, 0, 0, 0, 0}, // 8
{0, 0, 0, 0, 1, 0, 0} // 9
};
void setup() {
// Set segment pins as outputs
for (int i = 0; i < 7; i++) {
pinMode(segmentPins[i], OUTPUT);
}
}

void loop() {
for (int i = 0; i < 10; i++) {
displayDigit(i);
delay(1000); // Wait for 1 second
}
}
void displayDigit(int digit) {
// Set segments based on the digit
for (int i = 0; i < 7; i++) {
digitalWrite(segmentPins[i], digits[digit][i]);
}
}
8. To demonstrate the working of LCD Interface and the control under ARM Processor.

#include <LiquidCrystal.h>
LiquidCrystal lcd(D2, D3, D4, D5, D6, D7);
void setup()
{
lcd.begin(16, 2);
lcd.print("Hello, STM32!");
}
void loop()
{
lcd.setCursor(0, 1);
lcd.print("LCD Interface!");
delay(1000);
lcd.clear();
delay(1000);
}

9. To demonstrate the working of 16 channel ADC interface with LPC2929 Processor

You might also like