Posts

Showing posts from May, 2021

How to interface RGB LED with STM8S microcontroller.

Image
Problem Statement: How to interface RGB LED with STM8S microcontroller. Requirements: Hardware Requirements : 1Nos.STM8S module 1Nos. RGB LED 3Nos. 1KiloOhm Resistance Connecting Wires  Software Requirements : STVD STVP Cosmic C Compiler Code:   #include "stm8s.h" int main() {         // Default clock is HSI/8 = 2MHz GPIO_DeInit(GPIOD); // prepare Port B for working  GPIO_Init (GPIOD, GPIO_PIN_4, GPIO_MODE_OUT_PP_LOW_SLOW);            //Declare PB4 as push pull Output pin GPIO_Init (GPIOD, GPIO_PIN_5, GPIO_MODE_OUT_PP_LOW_SLOW);           //Declare PB5 as push pull Output pin GPIO_Init (GPIOD, GPIO_PIN_6, GPIO_MODE_OUT_PP_LOW_SLOW);          //Declare PB6 as push pull Output pin     TIM2_DeInit();     TIM2_TimeBaseInit(TIM2_PRESCALER_2048, 3500);     TIM2_Cmd(ENABLE);  while(TRUE)     {        ...

How to interface Buzzer with STM8S microcontroller.

Image
Problem Statement: How to interface Buzzer with STM8S microcontroller. Material Required:  Hardware: STM8S003F3P6 Module ST-LINK-V2 Programmer Buzzer BC547 NPN Transistor 1KOhm 1/4Watt Resistor Connecting Wire Software:  STVD STVP Cosmic CXSTM8 Special Edition 4.5.2 Compiler Hardware Setup: As you can see we are using a STM8S003F3P6 module for this problem. Since it is having onboard 3.3v regulator IC, which is sufficient for a buzzer to perform its operation. We should choose one pin for the output to give the signal for the buzzer. Here in the given schematic we had used D4. This D4 pin connected to the PNP transistor through a 1 kilo ohm resistor. We have connected the positive pin of the buzzer through the collector of the BC547 and negative pin to the ground.  Code:   #include "stm8s.h"  int main() {   // Default clock is HSI/8 = 2MHz GPIO_DeInit(GPIOD); // prepare Port B for working  GPIO_Init (GPIOD, GPIO_PIN_4, GPIO_MODE_OUT_PP_LOW_SLOW); //Dec...

How to write LED Blinking program on STM8S with timer 2 peripheral.

Image
As we know STM8S family microcontroller generally consists of  TIM2|TIM3|TIM5 general purpose timers. Here we have set a problem how to create a 1 Second LED ON/ LED OFF. For this we need to understand some feature which are as follows. Material Required: 1. STM8S Development Board (Here we are using STM8S003F3P6) 2. STM8 & STM32 ST-LINK V2 programmer Software Required: STVD (ST Visual Developer) STVP (ST Visual Programmer) Cosmic CXSTM8 Special Edition 4.5.2 Compiler Source files and Header files can be download from this link:  https://github.com/vivek889/STM8S /*STM8S003F3P6 LED BLINK PROGRAM WITH TIMER 2 (1 SECOND ON 1 SECOND OFF)*/ #include "stm8s.h" int main() {   // Default clock is HSI/8 = 2MHz GPIO_DeInit(GPIOB); // prepare Port B for working  GPIO_Init (GPIOB, GPIO_PIN_5, GPIO_MODE_OUT_PP_LOW_SLOW); //Declare PB5 as push pull Output pin TIM2_DeInit(); TIM2_TimeBaseInit(TIM2_PRESCALER_2048, 1952);  TIM2_Cmd(ENABLE);  while(TRUE)     {...

Embedded C program "Hello World"

Image
 To write a program in C first we should familiar with some basic C syntax. As you know, we always used to see this HELLO WORLD program, which gives some understanding the behavior of the language. #include <stdio.h> int main() {     printf("Hello World");   return 0; } To run this program we use compiler and debugger tool for C. GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, C#, VB, Perl, Swift, Prolog, JavaScript, Pascal, HTML, CSS, JS Code, Compile, Run and Debug online from anywhere in world. Every C program always having at least one main function, Here we can see there is a function i.e. called "main" function. This "main" function can be a collection of various function which are connected to each other to perform our desire task with the help of our microcontroller. Prototype of the main func tion : int main() Function na me                        ...