Es II Lab Manual
Es II Lab Manual
Es II Lab Manual
DEPT.OF ECE
PRAGNABHARATH
INSTITUTEOFTECHNOLOGY
MUDMYAL,CHEVELLA
DEPT.OF ECE
DEPT.OF ECE
DEPT.OF ECE
MUL R3,R2,R1
END
2. Write a program to configure Pin 19 of Port 0 as Output and want to
drive it High(Logic1)
#include <lpc214x.h>
int main(void)
{
IO0DIR |= (1<<19); // Config P0.19 as Ouput
While (1)
{
IO0SET |= (1<<19); // Make ouput High for P0.19
}
DEPT.OF ECE
DEPT.OF ECE
DEPT.OF ECE
DEPT.OF ECE
8. Write a program for toggling the port with delay using timer0.
Include <lpc214x.h>
void delay(void);
int main(void)
{
IO0DIR = 0xFFFFFFFF; // Configure all pins on Port 0 as Output
while(1)
{
IO0SET = 0xFFFFFFFF; // Turn on LEDs
delay();
IO0CLR = 0xFFFFFFFF; // Turn them off
delay();
}
return 0; // normally this wont execute
}
void delayMS(unsigned int milliseconds) //Using Timer0
{
T0TCR = 0x02; //Reset Timer
T0TCR = 0x01; //Enable timer
while(T0TC < milliseconds); //wait until timer counter reaches the desired delay
T0TCR = 0x00; //Disable timer
}
DEPT.OF ECE
//Enable timer
//Infinite Idle Loop
}
void initTimer0(void)
{
/*Assuming that PLL0 has been setup with CCLK = 60Mhz and PCLK also =
60Mhz.*/
//----------Configure Timer0------------T0CTCR = 0x0;
T0PR = PRESCALE-1;
60000 clock cycles
DEPT.OF ECE
void initClocks(void)
{
// This function is used to config PPL0 and setup both
// CPU and Peripheral clock @ 60Mhz
// You can find its definition in the attached files or case #2 source
}
DEPT.OF ECE
void init_PWM(void);
void init_Clocks(void);
int main(void)
{
init_Clocks();
init_PWM();
DEPT.OF ECE
void init_PWM(void)
{
/*Assuming that PLL0 has been setup with CCLK = 60Mhz and PCLK also = 60Mhz.*/
/*This is a per the Setup & Init Sequence given in the tutorial*/
PINSEL0 = (1<<1);
// Select PWM1 output for Pin0.0
PWMPCR = 0x0;
//Select Single Edge PWM - by default its single Edged so this line
can be removed
PWMPR = PWMPRESCALE-1;
// 1 micro-second resolution
PWMMR0 = 20000;
// 20ms = 20k us - period duration
PWMMR1 = 1000;
// 1ms - pulse duration i.e width
PWMMCR = (1<<1);
// Reset PWMTC on PWMMR0 match
PWMLER = (1<<1) | (1<<0);
// update MR0 and MR1
PWMPCR = (1<<9);
// enable PWM output
PWMTCR = (1<<1) ;
//Reset PWM TC & PR
PWMTCR = (1<<0) | (1<<3);
// enable counters and PWM Mode
//PWM Generation goes active now!!
//Now you can get the PWM output at Pin P0.0!
}
for (i=10000;i>0;i=i-100)
{
IO0SET = 0X00000080;
IO1SET = 0X00ff0000;
delay(i*10);
IO0CLR = 0X00000080;
IO1CLR = 0X00ff0000;
DEPT.OF ECE
delay(i*10);
}
}
}
void delay(unsigned long cnt)
{
unsigned long temp,val;
for(temp=0;temp<cnt;temp++)
for (val=0;val<10;val++);
}
NOTE:
1.
2.
3.
DEPT.OF ECE
DEPT.OF ECE
/* LPC21xx definitions*/
//#include "serial.h"
int main(void)
{
int j=0;
init_serial (); // initialise serial port with 9600bps
SendChar ('A'); // transmit char A
SendChar ('\n'); // transmit new line character
SendString("Ellenki"); // transmit string Ellenki
SendChar ('\n'); // transmit new line character
SendDigit(236); // transmit digit 236
}
void init_serial (void)
{
U0DLL = 0XC3;
U0DLM = 0X00;
U0LCR = 0X03;
/* DLAB = 0
*/
}
int GetChar (void)
{
*/
*/
DEPT.OF ECE
DEPT.OF ECE
DEPT.OF ECE
}
void init_lcd(void)
{
IO1DIR
|= 0x00FE0000;
Delay(200000) ;
Delay(100000);
write_command(0x30 << 16);
Delay(100000);
write_command(0x20 << 16);
lcd_command(0x01);
/* clear display */
lcd_command(0x06);
lcd_command(0x0c);
/* cursor off */
lcd_command(0x80);
/* first location */
}
void Delay(unsigned long b)
{
while (--b!=0);
}
void write_command(int cmd)
{
IO1CLR |= 0x00f00000;
IO1CLR |= 0x00040000;
// RW = 0
IO1CLR |= 0X00020000;
// RS= 0,
}
void write_data(int dat)
{
IO1CLR |= 0x00f00000;
IO1CLR |= 0x00040000;
IO1SET |= 0X00020000;
IO1SET |= 0x00f00000 & dat;
IO1SET |= 0X00080000;
Delay(30000);
IO1CLR |= 0x00080000;
}
void lcd_data(char dat)
{
write_data(dat << 16);
write_data(dat << 20);
}
void lcd_command(char cmd)
{
write_command(cmd << 16);
write_command(cmd << 20);
}
void printlcd(char *CPtr)
{
while(*CPtr != '\0')
{
lcd_data(*CPtr);
CPtr++;
Delay(20000); } }
DEPT.OF ECE
DEPT.OF ECE
{
IO0CLR = CLR;
IO0SET = O1;
delay(10);
if(check(I1))
{
lcd_data('0');
}
if(check(I2))
{
lcd_data('1');
}
if(check(I3))
{
lcd_data('2');
}
if(check(I4))
{
lcd_data('3');
}
IO0CLR = CLR;
IO0SET = O2;
if(check(I1))
{
lcd_data('4');
}
if(check(I2))
DEPT.OF ECE
{
lcd_data('5');
}
if(check(I3))
{
lcd_data('6');
}
if(check(I4))
{
lcd_data('7');
}
IO0CLR = CLR;
IO0SET = O3;
if(check(I1))
{
lcd_data('8');
}
if(check(I2))
{
lcd_data('9');
}
if(check(I3))
{
lcd_data('A');
}
if(check(I4))
DEPT.OF ECE
DEPT.OF ECE
{
lcd_data('B');
}
IO0CLR = CLR;
IO0SET = O4;
if(check(I1))
{
lcd_data('C');
}
if(check(I2))
{
lcd_data('D');
}
if(check(I3))
{
lcd_data('E');
}
if(check(I4))
{
lcd_data('F');
}
}
}
char check(int val)
/* scanning a a key
{
while((IO0PIN & 0X00003C00)==val)
{
*/
DEPT.OF ECE
delay(50);
if((IO0PIN & 0X00003C00)== 0X00003C00)return(1);
}
return(0) ;
}
void delay(int n)
*/
{
int i,j;
for (i=1; i<=n; i++)
for(j=0; j<=40000; j++);
}
void write_command(int cmd)
{
IO1CLR |= 0x00f00000;
/* Clear D4-D7 */
IO1CLR |= 0x00040000;
/* Read/Write = 0
IO1CLR |= 0X00020000;
IO1SET |= 0x00f00000 & cmd;
IO1SET |= 0X00080000;
*/
*/
Delay(30000);
IO1CLR |= 0x00080000;
/* set E to low */
}
void write_data(int dat)
{
IO1CLR |= 0x00f00000;
/* Clear D4-D7 */
IO1CLR |= 0x00040000;
/* Read/Write = 0
IO1SET |= 0X00020000;
*/
*/
DEPT.OF ECE
/* Enable = 1
}
void lcd_data(char dat)
{
write_data(dat << 16);
write_data(dat << 20);
}
void lcd_command(char cmd)
{
write_command(cmd << 16);
write_command(cmd << 20);
*/
//delay ~2ms
IO1CLR |= 0x00080000;
/* Set D4-D7
/* Set E to low
*/
*/
DEPT.OF ECE
Delay(200000) ;
write_command(0x28 << 16);
Delay(100000);
lcd_command(0x01);
/* clear display */
lcd_command(0x06);
lcd_command(0x0c);
/* cursor off */
lcd_command(0x80);
/* first location */