Posts

Showing posts with the label Embedded_C

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                        ...