0% found this document useful (0 votes)
12 views7 pages

WEEK - 3 Sudhanshu

The document contains multiple C code implementations for various functionalities using the LPC17xx microcontroller, including a watchdog timer, PWM signal generation, UART communication, and ADC operations. Each section of code is structured with initialization routines, main loops, and delay functions. The code snippets demonstrate practical applications such as LED control, signal modulation, and temperature measurement through ADC conversion.

Uploaded by

sudhaanshuu
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)
12 views7 pages

WEEK - 3 Sudhanshu

The document contains multiple C code implementations for various functionalities using the LPC17xx microcontroller, including a watchdog timer, PWM signal generation, UART communication, and ADC operations. Each section of code is structured with initialization routines, main loops, and delay functions. The code snippets demonstrate practical applications such as LED control, signal modulation, and temperature measurement through ADC conversion.

Uploaded by

sudhaanshuu
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

WEEK – 3

SUBMITTED BY

Sudhanshu Kumar

CL202408310180209

…………………………………………………………………………………………………………………………………………………………………………………..

DATE – 16TH DEC. 2024

// 1. WATCH DOG TIMER

#include <LPC17xx.h>

#include <stdint.h>

#define All_LED (0xFF<<19)

#define BUZZER (0x01<<27)

void delay_ms(uint32_t);

int main()

LPC_WDT->WDMOD |= (1<<1)|(1<<0); //Enable WDT and RESET microcontroller on TIME_OUT

LPC_WDT->WDCLKSEL &= ~0x03; //Select RC osillator as WDT clock i.e, 4MHz

LPC_WDT->WDTC = 8000000 ; //TIME_OUT = count*clock_rate => count =time_out/clock_rate = 4sec/ (.25us * 4) =


4000000;

LPC_WDT->WDFEED = 0xAA; //Start/Reload WDT

LPC_WDT->WDFEED = 0x55;

LPC_GPIO1->FIODIR |= All_LED;

LPC_GPIO1->FIODIR |= BUZZER;

LPC_GPIO1->FIOCLR |= All_LED;

LPC_GPIO1->FIOCLR |= BUZZER;

LPC_GPIO1->FIOSET |= BUZZER;

delay_ms(100);

LPC_GPIO1->FIOCLR |= BUZZER;

while(1)

LPC_GPIO1->FIOSET |= All_LED;

delay_ms(100);

//while(1);

LPC_GPIO1->FIOCLR |= All_LED;
delay_ms(100);

LPC_WDT->WDFEED = 0xAA; //Start/Reload WDT

LPC_WDT->WDFEED = 0x55;

void delay_ms(uint32_t millis)

uint32_t i , j ;

for(i=0; i < millis ; i++)

for(j=0; j < 1200 ; j++){}

DATE – 17th DEC. 2024

// De_Signal

#include <LPC17xx.h>

#include <stdint.h>

void delay_ms(uint32_t);

int main()

LPC_SC->PCONP |= (1 << 6);

LPC_PINCON->PINSEL3 |= (1 << 9);

LPC_PINCON->PINSEL3 &= ~(1 << 8);

LPC_PWM1->PCR |= (1 << 10);

LPC_PWM1->PCR |= (1 << 2);

LPC_PWM1->MCR |= (1 << 1);

LPC_PWM1->PR = 0;

LPC_PWM1->MR0 = 10000;

LPC_PWM1->MR1 = 2000;

LPC_PWM1->MR2 = 4000;

LPC_PWM1->LER |=(1 << 2)|(1 << 1)|(1 << 0);

LPC_PWM1->TCR |= (1 << 3)|(1 << 0);


while(1)

LPC_PWM1->MR1 = 2000;

LPC_PWM1->MR2 = 4000;

LPC_PWM1->LER |= (1 << 1)|(1 << 2);

delay_ms(200);

LPC_PWM1->MR1 = 2000;

LPC_PWM1->MR2 = 6000;

LPC_PWM1->LER |= (1 << 1)|(1 << 2);

delay_ms(200);

LPC_PWM1->MR1 = 2000;

LPC_PWM1->MR2 = 8000;

LPC_PWM1->LER |= (1 << 1)|(1 << 2);

delay_ms(1000);

LPC_PWM1->MR1 = 2000;

LPC_PWM1->MR2 = 9000;

LPC_PWM1->LER |= (1 << 1)|(1 << 2);

delay_ms(200);

void delay_ms (uint32_t millis)

uint32_t i , j ;

for ( i = 0 ; i < millis ; i++ ) {

for (j = 0 ; j < 1200 ; j++ ) {

}
//Se_Signal

#include <LPC17xx.h>

#include <stdint.h>

void delay_ms(uint32_t);

int main()

LPC_SC->PCONP |= (1 << 6); // Power-on PWM peripheral

LPC_PINCON->PINSEL3 |= (1 << 9);

LPC_PINCON->PINSEL3 &= ~(1 << 8);

LPC_PWM1->PCR |= (1 << 10); // Enable PWM1.2 channel

LPC_PWM1->PCR &= ~(1 << 2); // select single ege mode output

LPC_PWM1->MCR |= (1 << 1); // Repeat count on MR0 match

LPC_PWM1->PR = 0;

LPC_PWM1->MR0 = 10000; // PWM cycle = 10ms = 100Hz

LPC_PWM1->MR2 = 2000; // duty cycle = 20%

LPC_PWM1->LER |= (1 << 2)|(1 << 0); // load enable for MRR0 and MR2

LPC_PWM1->TCR |= (1 << 3)|(1 << 0); // Enable the timer counters in PWm mode

while(1)

LPC_PWM1->MR2 = 4000; // generate 40 %duty cycle signal

LPC_PWM1->LER |= (1 << 2);

delay_ms(500);

LPC_PWM1->MR2 = 8000; // genrate 80 %duty cycle signal

LPC_PWM1->LER |= (1 << 2);

delay_ms(500); }}

void delay_ms (uint32_t millis)

uint32_t i , j ;

for ( i = 0 ; i < millis ; i++ ) {

for (j = 0 ; j < 1200 ; j++ ) {

}}

}
DT – 18th Dec. 2024

//uart_keypress

#include <LPC17xx.h>

#include "lcd.h"

int main()

char ch ;

lcd_init();

LPC_SC->PCONP |= (1<<3); // power on uart0 module

LPC_PINCON->PINSEL0 |= (1<<4); // select P0.2 pin alteranet function as Uart0 TXD0 pin

LPC_PINCON->PINSEL0 &= ~(1<<5);

LPC_PINCON->PINSEL0 |= (1<<6); // select P0.3 pin alteranet function as Uart0 RXD0 pin

LPC_PINCON->PINSEL0 &= ~(1<<7);

LPC_UART0->LCR |= (1<<1)|(1<<0); // data length

LPC_UART0->LCR &= ~(1<<2); // single stop bit

LPC_UART0->LCR &= ~(1<<3); // No parity

LPC_UART0->LCR |= (1<<7); // divisor Latch enable

LPC_UART0->DLM = 0;

LPC_UART0->DLL = 6; // baut rate = pclk/16*DL = 1000000/16* (256 *DLM + DLL) = 1000000/(16 *6) = 10400

LPC_UART0->FDR |= (0x0C<<4)|(1<<0); // baut rate = pclk/16*DL(1+D/M) = 1000000/16* (256 *DLM + DLL)


(1+D/M) = 1000000/(16 *6 *(1+2/12)) = 9615

LPC_UART0->LCR &= ~(1<<7);

while(1)

while((LPC_UART0->LSR & (1 << 0) == 0)) { } // wait for data tranmission to complete

ch = LPC_UART0->RBR;

lcd_dat_write(ch);

}
//uart_rs

#include <LPC17xx.h>

#include "lcd.h"

void lcd_write_data(char data);

void delay_ms(uint32_t millis);

int main() {

char ch = 'A';

LPC_SC->PCONP |= (1 << 3);

LPC_PINCON->PINSEL0 |= (1 << 4);

LPC_PINCON->PINSEL0 &= ~(1 << 5);

LPC_PINCON->PINSEL0 |= (1 << 6);

LPC_PINCON->PINSEL0 &= ~(1 << 7);

LPC_UART0->LCR |= (1 << 1) | (1 << 0);

LPC_UART0->LCR &= ~(1 << 2);

LPC_UART0->LCR &= ~(1 << 3);

LPC_UART0->LCR |= (1 << 7);

LPC_UART0->DLM = 0;

LPC_UART0->DLL = 6;

LPC_UART0->FDR |= (0x0C << 4) | (1 << 0);

LPC_UART0->LCR &= ~(1 << 7);

while ((LPC_UART0->LSR & (1 << 5)) == 0) {}

ch = LPC_UART0->RBR;

lcd_dat_write(ch);

while (1);

}
DT – 19th Dec. 2024

#include<stdint.h>

#include<LPC17xx.h>

#include<stdio.h>

#include"uart0.h"

#define CH_SEL (1<<2)

#define CL_DIV (0xFF << 8)

#define B_MOD (0x01 << 16)

#define P_UP (0x01 << 21)

#define SC (0x01 << 24)

#define DN (0x01U << 31)

#define tc 100.0f

int main(){

uint32_t Su_val;

float volt, temp;

char Sval[16];

LPC_SC->PCONP |=(1<<12); //power on of adc

LPC_PINCON->PINSEL1 |=(1<<18); //p0 25 as ADC ch-2 input pin

LPC_PINCON->PINSEL1 &=~(1<<19); //p0 25 as ADC ch-2

LPC_ADC->ADCR|=CH_SEL; //select adc channel 2

LPC_ADC->ADCR&=~CL_DIV; // ADC = PCLK/(0+1)

LPC_ADC->ADCR&=~B_MOD; //Select ADC Software

LPC_ADC->ADCR|=P_UP; // make ADC Operation

uart0_init();

while(1){

LPC_ADC->ADCR|=SC;//start conversion

while((LPC_ADC->ADDR2 & DN)==0){}

Su_val = (LPC_ADC->ADDR2>>4) & 0XFFF;

volt = (Su_val) * (3.3/4096.0); // Convert to voltage

temp = volt * 100.0;

sprintf(Sval,"ADC Op: %.1f C", temp);

uart0_str_transmit(Sval);

delay_ms(2000);

new_line(); } }

You might also like