MICROCONTROLLERS (K5 & K6) have been studied

MICROCONTROLLERS
FOR EMBEDDED SYSTEMS LAB

 

NEC-655

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

 

/*
Experiment 1

AIM- WRITE A PROGRAM FOR BLINKING OF LED USING 8051
MICROCONTROLLER

 

REQUIREMENT- MICROCONTROLLER
KIT, POWER SUPPLY, CONNECTING
WIRES SOFTWARE
USED- KEIL MICROVISION 4, FLASH MAGIC. PROGRAM-

 

 

 

#include

 

void main()

{

unsigned int x;

 

for(;;)

{

P2=0x55;

for( x=0;x

void
main()

{

 

unsigned
int x;

for(;;)

{

P1=0X80;

for(x=0;x

sbit
LED1 =P1^0;

 

sbit
LED2 =P1^1;

 

//Function
Declaration

port_init();

InitINT0();

 

InitINT1();

//Main
Function

main()

{

port_init();

 

InitINT0();

InitINT1();

while(1)

{}

}

 

port_Init()

{

P0=0X00;

P1=0X00;

P2=0X00;

 

P3=0X0C;

}

InitINT0()
//int0 ISR

{

IT0=1;

 

EX0=1;

EA=1;

 

}

InitINT1()//INT1
ISR

{

IT1=1;

EX1=1;

 

EA=1;

}

external0_isr()interrupt
0

{

LED1
= ~LED1;

}

external1_isr()interrupt
2

 

{

LED2
= ~LED2;

}

 

OUTPUT:

 

The interrupts given at PORT
3 (P2.2 & P2.3) using PULL-UP KEYS (K5 & K6) have been studied
successfully:-

 

When K5 pressed – LED on.

When K5 pressed again – LED off.

Similarly,

 

When K6 pressed – LED on.

When K6 pressed again – LED off

/*Experiment
4

 

Objective: Write a program to
display temperature using internal sensor of MSP430 and display the same under
expressions in CCS.

 

 

#include

 

#define
CALADC12_15V_30C *((unsigned int *)0x1A1A) //
Temperature Sensor Calibration-30 C //See device datasheet for TLV table memory
mapping

#define CALADC12_15V_85C *((unsigned int *)0x1A1C)   // Temperature Sensor Calibration-85 C

 

unsigned
long temp;

volatile
float temperatureDegC;

 

volatile
float temperatureDegF;

 

int
main(void)

{

WDTCTL = WDTPW + WDTHOLD;                   // Stop WDT

 

REFCTL0 &= ~REFMSTR;                          // Reset
REFMSTR to hand over control to

// 
ADC12_A
ref control registers

ADC12CTL0 = ADC12SHT0_8 + ADC12REFON + ADC12ON;

// 
Internal
ref = 1.5V

ADC12CTL1 = ADC12SHP;                       // enable
sample timer

 

ADC12MCTL0 = ADC12SREF_1 + ADC12INCH_10;  // ADC i/p ch A10 = temp sense i/p

 

ADC12IE = 0x001; // ADC_IFG
upon conv result-ADCMEMO __delay_cycles(100); // delay to allow Ref to settle
ADC12CTL0 |= ADC12ENC;

 

while(1)

{

 

ADC12CTL0 &= ~ADC12SC;
ADC12CTL0 |= ADC12SC;

 

 

//
Sampling and conversion start

 

 

__bis_SR_register(LPM0_bits +
GIE); // LPM0 with interrupts enabled __no_operation();

 

// 
Temperature
in Celsius. See the Device Descriptor Table section in the

// 
System
Resets, Interrupts, and Operating Modes, System Control Module

// 
chapter
in the device user’s guide for background information on the

// 
used
formula.

 

temperatureDegC =
(float)(((long)temp – CALADC12_15V_30C) * (85 – 30)) / (CALADC12_15V_85C –
CALADC12_15V_30C) + 30.0f;

 

//Temperature in
Fahrenheit Tf = (9/5)*Tc + 32 temperatureDegF = temperatureDegC * 9.0f / 5.0f +
32.0f;

 

__no_operation();                         // SET
BREAKPOINT HERE

 

}

}

#pragma
vector=ADC12_VECTOR

__interrupt
void ADC12ISR (void)

 

{

switch(__even_in_range(ADC12IV,34))

{

case 0: break;                                // Vector 0:  No interrupt

case 2: break;                                // Vector 2:  ADC overflow

 

case 4: break;                                // Vector 4:  ADC timing overflow

case
6:

// Vector  6:  ADC12IFG0

temp = ADC12MEM0;

// Move results, IFG is cleared

__bic_SR_register_on_exit(LPM0_bits);  // Exit active CPU

break;

 

 

case
8: break;

// Vector

8:  ADC12IFG1

case
10: break;

// Vector

10: ADC12IFG2

case
12: break;

// Vector

12: ADC12IFG3

case
14: break;

// Vector

14: ADC12IFG4

case
16: break;

// Vector

16: ADC12IFG5

case
18: break;

// Vector

18: ADC12IFG6

case
20: break;

// Vector

20: ADC12IFG7

case
22: break;

// Vector

22: ADC12IFG8

case
24: break;

// Vector

24: ADC12IFG9

case
26: break;

// Vector

26: ADC12IFG10

case
28: break;

// Vector

28: ADC12IFG11

case
30: break;

// Vector

30: ADC12IFG12

case
32: break;

// Vector

32: ADC12IFG13

case
34: break;

// Vector 34: ADC12IFG14

default:
break;

 

 

}

}

/*
Experiment 5

AIM:
Generation of ramp waveform using DAC and 8051microcontroller.

 

REQUIREMENTS:

 

SOFTWARE USED: Keil ?vision4, Flash magic

 

HARDWARE USED: Micro controller kit
8051, connecting wires and power supply

 

 

#include

void main()

{unsigned int i;

while(1)

{for(i=0;i

void main(void)

{

unsigned int i=0;

WDTCTL = WDTPW | WDTHOLD;

P1DIR |= 0x01; // Led is attached to P1.0

P4DIR |= 0x80;// Led is attched to P1.7

 

for(;;)

 

{

P1OUT ^= 0x01; //Toggle led p1.0

P4OUT ^= 0x80; //Toggle led p1.7

 

for(i=0;i

void main( void )

{

 

unsigned int i=0;

WDTCTL = WDTPW | WDTHOLD;

 

//SW1 -P1.1, SW2- P2.1, LED1- P1.0, LED2- P4.7
P1REN |= 0x02; // Enable resistor on P1.1 P1OUT = 0x03; //Set resistor to
pull-up, P1.0 high P1DIR = 0x01; //P1.0 as output & P1.1 as intput

 

P2REN |= 0x02; // Enable resistor on P2.1

P2OUT  =
0x02; // Set resistor to pull-up

P2DIR = 0x01;

 

 

P4OUT  =
0x80; // Set P4.7 high

P4DIR = 0x80; // Set P4.7 as output

 

while(1)

{

if(!(P1IN & 0x02)) // If push button is
pressed

{

P4OUT ^= 0x80;

}

if(!(P2IN & 0x02))

 

{

P1OUT ^= 0x01;

 

}

 

for(i=0;i

 

void main(void)

{

 

WDTCTL = WDTPW + WDTHOLD;

 

// Stop WDT

 

 

/*** GPIO Set-Up ***/

P1DIR |= BIT2;  //

P1SEL |= BIT2; //SELECTION OF PERIPHERAL

 

P1DIR |= BIT3;

P1SEL |= BIT3;

 

/*** Timer0_A Set-Up ***/

TA0CCR0 |= 200 – 1;

TA0CCTL1 |= OUTMOD_7;

TA0CCR1 |= 100;

TA0CTL |= TASSEL_2 + MC_1;

 

/*** Timer1_A Set-Up ***/

 

TA0CCR0 |= 1000 – 1;

TA0CCTL2 |= OUTMOD_7;

TA0CCR2 |= 500;

TA0CTL |= TASSEL_2 + MC_1;

return 0;

 

}

 

OUTPUT:

/* Experiment 10

 

Objective:
Setting up CC3100 as an HTTP server.

 

/*

 

WiFi Web Server LED Blink

 

A simple web server
that lets you blink an LED via the web. This sketch will print the IP address
of your WiFi (once connected) to the Serial monitor. From there, you can open
that address in a web browser to turn on and off the LED on pin 9.

 

If the IP address of your WiFi is your
Address:

 

http://yourAddress/H turns the LED on

 

http://yourAddress/L turns it off

 

This example is written for a network using
WPA encryption. For WEP or WPA, change the Wifi.begin()

 

call accordingly.

 

Circuit:

 

* CC3200 WiFi LaunchPad or CC3100 WiFi BoosterPack with TM4C or MSP430
LaunchPad */

 

#ifndef __CC3200R1M1RGC__

 

//  Do
not include SPI for CC3200 LaunchPad #include

 

#endif

 

#include

 

//  your
network name also called SSID

 

char ssid = “Vishal”;

 

//  your
network password char password = “12341234”;

 

//  your
network key Index number (needed only for WEP) int keyIndex = 0;

 

WiFiServer server(80);

 

void setup() {

 

Serial.begin(9600);
// initialize serial communication pinMode(RED_LED, OUTPUT); // set the LED pin
mode

 

// attempt
to connect to Wifi network: Serial.print(“Attempting to connect to Network
named: “);

 

// print
the network name (SSID);

 

Serial.println(ssid);

 

// Connect
to WPA/WPA2 network. Change this line if using open or WEP network:
WiFi.begin(ssid, password);

 

while ( WiFi.status() != WL_CONNECTED) {

 

//  print
dots while we wait to connect

 

Serial.print(“.”);

 

delay(300);

 

}

 

Serial.println(”
You’re connected to the
network”);

 

Serial.println(“Waiting for an ip
address”);

 

while (WiFi.localIP() == INADDR_NONE) {

 

//  print
dots while we wait for an ip addresss Serial.print(“.”);

 

delay(300);

 

}

 

Serial.println(”
IP Address
obtained”);

 

// you’re
connected now, so print out the status printWifiStatus();

 

Serial.println(“Starting webserver on
port 80”);

 

server.begin();
// start the web server on port 80 Serial.println(“Webserver
started!”);

 

}

 

void loop() {

 

int i = 0;

 

WiFiClient client = server.available();  // listen for incoming clients

 

if
(client) {                               // if you
get a client,

 

Serial.println(“new
client”);           // print a message out the serial port

 

char
buffer150 = {0};                  // make a buffer to hold incoming data

 

while
(client.connected()) {           // loop while the client’s connected

 

if
(client.available()) {             // if
there’s bytes to read from the client,

 

char
c = client.read();             // read a byte, then

 

Serial.write(c);                     //
print it out the serial monitor

 

if
(c == ‘
‘) {                     // if the byte is a newline character

 

//  if
the current line is blank, you got two newline characters in a row.

 

//  that’s
the end of the client HTTP request, so send a response:

if
(strlen(buffer) == 0) {

 

//  HTTP
headers always start with a response code (e.g. HTTP/1.1 200 OK)

 

//  and
a content-type so the client knows what’s coming, then a blank line:
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-type:text/html”);

 

client.println();

 

//   the content of the HTTP response follows the
header: client.println(“

CC3100 WiFi<br> Web Server“);

 

client.println(“

Welcome to the CC3100 WiFi Web
Server

“);

 

client.println(“

MIET, MEERUT

“); client.println(“

EC-VI
A/B/C

“); client.print(“RED LED “);
client.println(”
“);

 

//  The
HTTP response ends with another blank line: client.println();

 

//  break
out of the while loop:

 

break;

 

}

 

else
{      // if you got a newline, then clear the buffer:

 

memset(buffer, 0, 150);

 

i = 0;

 

}

 

}

 

else if (c != ‘
‘) { bufferi++ = c;

 

}

 

 

 

 

//  
if you got anything else but a carriage return
character,

 

//  add
it to the end of the currentLine

 

 

// Check
to see if the client request was “GET /H” or “GET /L”: if
(endsWith(buffer, “GET /H”)) {

 

digitalWrite(RED_LED,
HIGH);                // GET /H turns the LED on

 

}

 

if (endsWith(buffer, “GET /L”)) {

 

digitalWrite(RED_LED,
LOW);                 //
GET /L turns the LED off

 

}

 

}

 

}

 

// close the connection:

 

client.stop();

Serial.println(“client
disonnected”);

 

}

 

}

 

//

 

//a way to check if one array ends with another array

 

//

 

boolean endsWith(char* inString, char* compString) { int compLength =
strlen(compString);

 

int strLength = strlen(inString);

 

//compare
the last “compLength” values of the inString int i;

 

for (i = 0; i