Sei sulla pagina 1di 20

green led on

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

int main (void)

*RCC_AHBENR |= 0x02; /* Enable GPIOB clock */

*GPIOB_MODER |= 0x5000;

*GPIOB_BSRRL =1ul<<7 ;/* green led on*/

green off

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

int main (void)

*RCC_AHBENR |= 0x02; /* Enable GPIOB clock */

*GPIOB_MODER |= 0x5000;

*GPIOB_BSRRL =1ul<<23;/* green led off*/

}
blue led on

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

int main (void)

*RCC_AHBENR |= 0x02; /* Enable GPIOB clock */

*GPIOB_MODER |= 0x5000;

*GPIOB_BSRRL =1ul<<6 ;/* blue led on*/

blue led off

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

int main (void)

*RCC_AHBENR |= 0x02; /* Enable GPIOB clock */

*GPIOB_MODER |= 0x5000;

*GPIOB_BSRRL =1ul<<22 ;/* blue led off*/

}
both leds on

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

int main (void)

*RCC_AHBENR |= 0x02; /* Enable GPIOB clock */

*GPIOB_MODER |= 0x5000;

*GPIOB_BSRRL =3ul<<6 ;/* blue led on*/

both leds off

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

int main (void)

*RCC_AHBENR |= 0x02; /* Enable GPIOB clock */

*GPIOB_MODER |= 0x5000;

*GPIOB_BSRRL =3ul<<22;/* blue led off*/

}
led blink using software delay only once

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

int i;

int main (void)

*RCC_AHBENR |= 0x02; /* Enable GPIOB clock */

*GPIOB_MODER |= 0x5000;

*GPIOB_BSRRL =3ul<<6;/* blue led on*/

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

*GPIOB_BSRRL =3ul<<22;/* blue led off*/

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

}
led blink using software delay continuously

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

int i;

int main (void)

*RCC_AHBENR |= 0x02; /* Enable GPIOB clock */

*GPIOB_MODER |= 0x5000;

while(1) // TO TOGGLE THE LEDS CONTINEOUSLY

*GPIOB_BSRRL =3ul<<6;/* blue led on*/

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

*GPIOB_BSRRL =3ul<<22;/* blue led off*/

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

}
toggle using exor operation and odr register

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

#define GPIOB_ODR (uint32_t*) (0x40020400 + 0x14)

int i;

int main (void)

*RCC_AHBENR |= 0x02; /* Enable GPIOB clock */

*GPIOB_MODER |= 0x5000;

while(1)

*GPIOB_ODR ^=0XC0;/* blue and green led on and off*/

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

}
TOGGLE USING TIMER

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

#define GPIOB_ODR (uint32_t*) (0x40020400 + 0x14)

#define RCC_APB1ENR (uint32_t*) (0x40023800 + 0x000024)

#define TIM2_CNT (uint32_t*) (0x40000000 + 0x24)

#define TIM2_ARR (uint32_t*) (0x40000000 + 0x2C)

#define TIM2_PSC (uint32_t*) (0x40000000 + 0x28)

#define TIM2_CR1 (uint32_t*) (0x40000000 + 0x00)

int i;

int main (void)

*RCC_AHBENR |= 0x02; /* Enable GPIOB clock */

*GPIOB_MODER |= 0x5000;

*RCC_APB1ENR = 0X1;

*TIM2_ARR =49999;

*TIM2_PSC =79;

*TIM2_CR1 =0X81;

while(1)

if(*TIM2_CNT == *TIM2_ARR)
{

*GPIOB_ODR ^=0Xc0; /* blue and green led on and off*/

*TIM2_CNT =0;

TOGGLE USING TIMER (SR REGISTER)

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

#define GPIOB_ODR (uint32_t*) (0x40020400 + 0x14)

#define RCC_APB1ENR (uint32_t*) (0x40023800 + 0x000024)

#define TIM2_CNT (uint32_t*) (0x40000000 + 0x24)

#define TIM2_ARR (uint32_t*) (0x40000000 + 0x2C)

#define TIM2_PSC (uint32_t*) (0x40000000 + 0x28)

#define TIM2_CR1 (uint32_t*) (0x40000000 + 0x00)

#define TIM2_SR (uint32_t*) (0x40000000 + 0x10)

int i;

int main (void)

*RCC_AHBENR |= 0x02; /* Enable GPIOB clock */


*GPIOB_MODER |= 0x5000;

*RCC_APB1ENR = 0X1;

*TIM2_ARR =49999;

*TIM2_PSC =79;

*TIM2_CR1 =0X81;

while(1)

if(*TIM2_SR & 0X01)

*GPIOB_ODR ^=0X40; /* blue and green led on and off*/

*TIM2_SR =0;

USER SWITCH

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

#define GPIOB_ODR (uint32_t*) (0x40020400 + 0x14)

#define GPIOA_MODER (uint32_t*) (0x40020000 + 0x00)

#define GPIOA_IDR (uint32_t*) (0x40020000 + 0x10)


#define GPIOA_PUPDR (uint32_t*) (0x40020000 + 0x0C)

#define RCC_APB1ENR (uint32_t*) (0x40023800 + 0x000024)

#define TIM2_CNT (uint32_t*) (0x40000000 + 0x24)

#define TIM2_ARR (uint32_t*) (0x40000000 + 0x2C)

#define TIM2_PSC (uint32_t*) (0x40000000 + 0x28)

#define TIM2_CR1 (uint32_t*) (0x40000000 + 0x00)

#define TIM2_SR (uint32_t*) (0x40000000 + 0x10)

int i;

int main (void)

*RCC_AHBENR |= 0x03; /* Enable GPIOB clock */

*GPIOB_MODER |= 0x5000;

*GPIOA_MODER|=0X00;

*GPIOA_PUPDR|=0X2;

//*RCC_APB1ENR = 0X1;

//*TIM2_ARR =49999;

//*TIM2_PSC =79;

//*TIM2_CR1 =0X81;

while(1)

if(*GPIOA_IDR & 0X01)


*GPIOB_ODR =0XC0;

HARDWARE DELAY LED SWITCHING FROM GREEN TO BLUE WITH 20 SEC

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

#define GPIOB_ODR (uint32_t*) (0x40020400 + 0x14)

#define GPIOA_MODER (uint32_t*) (0x40020000 + 0x00)

#define GPIOA_IDR (uint32_t*) (0x40020000 + 0x10)

#define GPIOA_PUPDR (uint32_t*) (0x40020000 + 0x0C)

#define RCC_APB1ENR (uint32_t*) (0x40023800 + 0x000024)

#define TIM2_CNT (uint32_t*) (0x40000000 + 0x24)

#define TIM2_ARR (uint32_t*) (0x40000000 + 0x2C)

#define TIM2_PSC (uint32_t*) (0x40000000 + 0x28)

#define TIM2_CR1 (uint32_t*) (0x40000000 + 0x00)

#define TIM2_SR (uint32_t*) (0x40000000 + 0x10)

int i,count=1;

int main (void)


{

*RCC_AHBENR |= 0x03; /* Enable GPIOB clock */

*GPIOB_MODER |= 0x5000;

*GPIOA_MODER|=0X00;

*GPIOA_PUPDR|=0X2;

*RCC_APB1ENR = 0X1;

*TIM2_ARR =49999;

*TIM2_PSC =199;

*TIM2_CR1 =0X81;

while(1)

if(*GPIOA_IDR & 0X01)

if((count%2 )!=0)

*GPIOB_ODR=0X80;

while(*TIM2_ARR != *TIM2_CNT);

*GPIOB_ODR=0X00;

*GPIOB_ODR=0X40;

else
{

*GPIOB_ODR=0X00;

*GPIOB_ODR=0X80;

while(*TIM2_ARR != *TIM2_CNT);

*GPIOB_ODR=0X00;

*GPIOB_ODR=0X40;

count++;

USART 1 TRANSMISSION POLLYING METHOD


typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

#define GPIOB_ODR (uint32_t*) (0x40020400 + 0x14)

#define GPIOA_MODER (uint32_t*) (0x40020000 + 0x00)

#define GPIOA_AFRH (uint32_t*) (0x40020000 + 0x24)

#define RCC_APB2ENR (uint32_t*) (0x40023800 + 0x000020)

#define USART1_BRR (uint32_t*) (0x40013800 + 0x08)


#define USART1_CR1 (uint32_t*) (0x40013800 + 0x0C)

#define USART1_SR (uint32_t*) (0x40013800 + 0x00)

#define USART1_DR (uint32_t*) (0x40013800 + 0x04)

int i,j;

char ch[] ="INTERNSHIP@NIELIT\r";

int main (void)

*RCC_AHBENR |= 0x03; /* Enable GPIOB clock */

*RCC_APB2ENR |=0X4000;

*GPIOB_MODER |= 0x5000;

*GPIOA_MODER|=0X280000;

*GPIOA_AFRH=0X770;

*USART1_BRR = 0XD0;

*USART1_CR1 = 0X2008;

while(1)

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

{
*USART1_DR=ch[i];

while((*USART1_SR & 0X80) ==0);

for(j=0;j<50000;j++);

WITH SRTING.H

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

#define GPIOB_ODR (uint32_t*) (0x40020400 + 0x14)

#define GPIOA_MODER (uint32_t*) (0x40020000 + 0x00)

#define GPIOA_AFRH (uint32_t*) (0x40020000 + 0x24)

#define RCC_APB2ENR (uint32_t*) (0x40023800 + 0x000020)

#define USART1_BRR (uint32_t*) (0x40013800 + 0x08)

#define USART1_CR1 (uint32_t*) (0x40013800 + 0x0C)

#define USART1_SR (uint32_t*) (0x40013800 + 0x00)

#define USART1_DR (uint32_t*) (0x40013800 + 0x04)


int i,j;

char ch[] ="INTERNSHIP@NIELIT\r";

int main (void)

*RCC_AHBENR |= 0x03; /* Enable GPIOB clock */

*RCC_APB2ENR |=0X4000;

*GPIOB_MODER |= 0x5000;

*GPIOA_MODER|=0X280000;

*GPIOA_AFRH=0X770;

*USART1_BRR = 0XD0;

*USART1_CR1 = 0X2008;

while(1)

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

*USART1_DR=ch[i];

while((*USART1_SR & 0X80) ==0);

for(j=0;j<50000;j++);

}
USART RECEPTION

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

#define GPIOB_ODR (uint32_t*) (0x40020400 + 0x14)

#define GPIOA_MODER (uint32_t*) (0x40020000 + 0x00)

#define GPIOA_AFRH (uint32_t*) (0x40020000 + 0x24)

#define RCC_APB2ENR (uint32_t*) (0x40023800 + 0x000020)

#define USART1_BRR (uint32_t*) (0x40013800 + 0x08)

#define USART1_CR1 (uint32_t*) (0x40013800 + 0x0C)

#define USART1_SR (uint32_t*) (0x40013800 + 0x00)

#define USART1_DR (uint32_t*) (0x40013800 + 0x04)

#include<string.h>

int i=0,j;

char ch,a[100];

int main (void)

*RCC_AHBENR |= 0x03; /* Enable GPIOB clock */

*RCC_APB2ENR |=0X4000;
*GPIOB_MODER |= 0x5000;

*GPIOA_MODER|=0X280000;

*GPIOA_AFRH=0X770;

*USART1_BRR = 0XD0;

*USART1_CR1 = 0X200C;

while(1)

if(*USART1_SR & 0X20)

ch= *USART1_DR ;

USART TRANSMISSION AND RECEPTION COMBINED

typedef unsigned int uint32_t;

#define RCC_AHBENR (uint32_t*) (0x40023800 + 0x00001C)

#define GPIOB_MODER (uint32_t*) (0x40020400 + 0x00)

#define GPIOB_BSRRL (uint32_t*) (0x40020400 + 0x18)

#define GPIOB_ODR (uint32_t*) (0x40020400 + 0x14)


#define GPIOA_MODER (uint32_t*) (0x40020000 + 0x00)

#define GPIOA_AFRH (uint32_t*) (0x40020000 + 0x24)

#define RCC_APB2ENR (uint32_t*) (0x40023800 + 0x000020)

#define USART1_BRR (uint32_t*) (0x40013800 + 0x08)

#define USART1_CR1 (uint32_t*) (0x40013800 + 0x0C)

#define USART1_SR (uint32_t*) (0x40013800 + 0x00)

#define USART1_DR (uint32_t*) (0x40013800 + 0x04)

#include<string.h>

int i=0,j;

char ch,a[100];

int main (void)

*RCC_AHBENR |= 0x03; /* Enable GPIOB clock */

*RCC_APB2ENR |=0X4000;

*GPIOB_MODER |= 0x5000;

*GPIOA_MODER|=0X280000;

*GPIOA_AFRH=0X770;

*USART1_BRR = 0XD0;
*USART1_CR1 = 0X200C;

while(1)

if(*USART1_SR & 0X20)

ch= *USART1_DR ;

a[i]=ch;

*USART1_DR =a[i];

i++;

Easy codes by suresh kumar 

Potrebbero piacerti anche