Hesam Moshiri
Published © CC BY-NC-ND

Programmable Police LED Flasher Using an STM8

Programmable police LED flasher using an STM8 [36+36 LEDs].

IntermediateFull instructions provided3 hours3,238
Programmable Police LED Flasher Using an STM8

Things used in this project

Hardware components

STMicroelectronics STM8s001j3
×1

Story

Read more

Schematics

fig1_xGosT9hS6e.jpg

Code

Code

C/C++
#include "stm8s.h"

void Delay(uint16_t cy);
void Program_1(void);
void Program_2(void);
void Program_3(void);
void ResetPins(void);


int counter = 0;	


void main(void)
{
	
	GPIO_DeInit(GPIOD);
  GPIO_DeInit(GPIOB);
	
	GPIO_Init(GPIOA, GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST); 
	GPIO_Init(GPIOD, GPIO_PIN_6, GPIO_MODE_OUT_PP_LOW_FAST);
	
	GPIO_Init(GPIOB, GPIO_PIN_4, GPIO_MODE_IN_FL_IT);
	
	EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOB, EXTI_SENSITIVITY_FALL_ONLY);
	EXTI_SetTLISensitivity(EXTI_SENSITIVITY_FALL_ONLY);
	
	enableInterrupts();
	
				
	while (1)
	{		
		
	switch(counter)
	{
		case 0:
      ResetPins(); 		
		  Program_1();
			break;
		case 1:
		  ResetPins();
		  Program_2();
			break;
    case 2:
		  ResetPins();
		  Program_3();
      break;			
	}
	
  }
}

void ResetPins(void)
{
	GPIO_WriteLow(GPIOD, GPIO_PIN_6);
	GPIO_WriteLow(GPIOA, GPIO_PIN_3);	
}

void Delay(uint16_t cy)
{
    do{
        --cy;
    }while(cy);
}

void Program_1(void)
{
	int i = 0;
	
			
	for (i = 0; i < 12; i++)
		{
		  GPIO_WriteReverse(GPIOA, GPIO_PIN_3);
		  Delay(20000);
	  }
	
		ResetPins();
		Delay(10000);
				
		for (i = 0; i < 12; i++)
		{
		  GPIO_WriteReverse(GPIOD, GPIO_PIN_6);
		  Delay(20000);
	  }
		
		ResetPins();
		Delay(10000);    		
	
}

void Program_2(void)
{
	int i = 0;	
			
	for (i = 0; i < 24; i++)
		{
		  GPIO_WriteReverse(GPIOA, GPIO_PIN_3);
		  Delay(10000);
	  }
	
		ResetPins();
		Delay(8000);		
		
		for (i = 0; i < 24; i++)
		{
		  GPIO_WriteReverse(GPIOD, GPIO_PIN_6);
		  Delay(10000);
	  }
		
		ResetPins();
		Delay(8000);    		
	
}

void Program_3(void)
{
	unsigned int i = 0;	
		
	for (i = 15000; i > 1000; i = i - 250)
		{
		  GPIO_WriteReverse(GPIOA, GPIO_PIN_3);
		  Delay(i);
	  }
	
		ResetPins();
		Delay(8000);		
		
		for (i = 15000; i > 1000; i = i - 250)
		{
		  GPIO_WriteReverse(GPIOD, GPIO_PIN_6);
		  Delay(i);
	  }
		
		ResetPins();		
		Delay(8000);
	
}

Credits

Hesam Moshiri

Hesam Moshiri

18 projects • 9 followers

Comments