Timer
What is a Timer ?
A Timer is device it sense the
time interval and produce an output at a set value . example alarm Timer setting.(
Timer in Wikipedia )
,What is the need of a timer in Micro controller ?
1) Some time micro controller Code need some accurate
Delay ( Example blinking An LED in each accurate 1 sec.
Look LED Blinking example2)Some Time the code needs the code
Repeat 3) Most of the
Interfacing devices with micro-controller needs a clock (accurate interval of clocks)
Example: LCD module require Clock Signal
Look LCD Interfacing Timer in 8051
Also a Timer actually require a clock pulse (pling) .These pulse are given from controller (actually it is in software based not giving ) see below picture
8051 type controller has two Timer Timer 0 and Timer 1 (These two timer is the length of 16 bit ,0000 to FFFF ).These Timer is named as TR0 and TR1.
The Timer Setting/configuring can controlling by the TMOD register
These TMOD register Values is used to decide how the Timer Works .
Sample program
Timer
What is a Timer ?
A Timer is device it sense the
time interval and produce an output at a set value . example alarm Timer setting.(
Timer in Wikipedia )
,What is the need of a timer in Micro controller ?
1) Some time micro controller Code need some accurate
Delay ( Example blinking An LED in each accurate 1 sec.
Look LED Blinking example
2)Some Time the code needs the code
Repeat
3) Most of the
Interfacing devices with micro-controller needs a clock (accurate interval of clocks)
Example: LCD module require Clock Signal
Look LCD Interfacing
Timer in 8051
Also a Timer actually require a clock pulse (pling) .These pulse are given from controller (actually it is in software based not giving ) see below picture
8051 type controller has two Timer Timer 0 and Timer 1 (These two timer is the length of 16 bit ,0000 to FFFF ).These Timer is named as TR0 and TR1.
The Timer Setting/configuring can controlling by the TMOD register
These TMOD register Values is used to decide how the Timer Works .
Sample program
Switch Bounce
Microcontrolers may not in Human thinking frequency .Human thinking frequency is lies in some of low Hz . Microcontroler works variety range of frequency ie ,12Mhz,20 Mhz etc . In a push Button micro controller interfacing, Human and Micro controller are feels that whether the push is pressed or not in different way as follows in the graph .
Some small duration pulse due to denounce generated as multiple touch error
Hardware solution It can be made by a resistor and a capacitor in the following manner or any other for comfortable
When ever the switch is pressed the capacitor will charge rapidly ,practically the first charge wil be across the ,capacitor ,
So we can avoid the denouncing effect .
The capacitor and the resistor will be select in accordance with time constant . as follows
Will be update
Switch Bounce
Microcontrolers may not in Human thinking frequency .Human thinking frequency is lies in some of low Hz . Microcontroler works variety range of frequency ie ,12Mhz,20 Mhz etc . In a push Button micro controller interfacing, Human and Micro controller are feels that whether the push is pressed or not in different way as follows in the graph .
Some small duration pulse due to denounce generated as multiple touch error
Hardware solution
It can be made by a resistor and a capacitor in the following manner or any other for comfortable
When ever the switch is pressed the capacitor will charge rapidly ,practically the first charge wil be across the ,capacitor ,
So we can avoid the denouncing effect .
The capacitor and the resistor will be select in accordance with time constant . as follows
Will be update
Parallel to serial Interfacing with Micro controller
Interfacing with 74HC165 with 8051
I am trying to make multiple input with using minimum input port of micro controller ,ie 3 wire .
By using a 3 wire we can interface more input as we wish.
I am making a tutorial for it , Basics of 74HC165 which is a parallel to serial shift register .
Only three pin is connected with this IC .
1) SH/LD or PL is used load parallel data to the IC .A low pulse (ground) is applied for store the parallel data at the pin from A to H . And a High (5 Volt) is applied to stop the reading from the PIN A to H .
2) Then to read the loaded or saved data to Micro controller we have to give clock to the PIN 2 of 74HC165 (CLK) . 8 pulses is applied to read 8 bit (Pin A to B)
3) QH / SO . serial out pin is used to get the stored parallel data to serially.
The CLK INH pin must be connect in ground for enable clock.
To use cascaded 74HC165 for increasing i/p .connect the Seriall output pin (PIN 9) of first satge into serial input of first stage see the following circuit.
see the code below
#include
#include
#include "lcd.h"
sbit PL = P1^0; // Loading parallel data to HC165.
sbit CLK = P1^1; // Clock pulse to HC165.
sbit Beep = P1^2; //
sbit data_in = P1^3;
void clock(void);
void display(unsigned char value);
void main()
{
unsigned char position ,no_of_ip = 17;
lcd_init();
string(" gElectron");
while(1)
{
PL = 0 ;
delay(2);
PL = 1;
for(position = 1; no_of_ip > position; position++ , clock())
{
if(data_in == 1)
display(position);
}
}
}
void clock(void)
{
CLK = 1;
delay(1);
CLK = 0;
}
void display(unsigned int value)
{
unsigned int a[1];
Beep = 1;
lcd_init();
lcd_cmd(0x01);
string("Pressed key ");
lcd_cmd(0xc0);
sprintf(a,"%d",value);
string(a);
delay(1);
Beep = 0;
}
Download the whle file here
github.
Parallel to serial Interfacing with Micro controller
Interfacing with 74HC165 with 8051
I am trying to make multiple input with using minimum input port of micro controller ,ie 3 wire .
By using a 3 wire we can interface more input as we wish.
I am making a tutorial for it , Basics of 74HC165 which is a parallel to serial shift register .
Only three pin is connected with this IC .
1) SH/LD or PL is used load parallel data to the IC .A low pulse (ground) is applied for store the parallel data at the pin from A to H . And a High (5 Volt) is applied to stop the reading from the PIN A to H .
2) Then to read the loaded or saved data to Micro controller we have to give clock to the PIN 2 of 74HC165 (CLK) . 8 pulses is applied to read 8 bit (Pin A to B)
3) QH / SO . serial out pin is used to get the stored parallel data to serially.
The CLK INH pin must be connect in ground for enable clock.
To use cascaded 74HC165 for increasing i/p .connect the Seriall output pin (PIN 9) of first satge into serial input of first stage see the following circuit.
see the code below
#include
#include
#include "lcd.h"
sbit PL = P1^0; // Loading parallel data to HC165.
sbit CLK = P1^1; // Clock pulse to HC165.
sbit Beep = P1^2; //
sbit data_in = P1^3;
void clock(void);
void display(unsigned char value);
void main()
{
unsigned char position ,no_of_ip = 17;
lcd_init();
string(" gElectron");
while(1)
{
PL = 0 ;
delay(2);
PL = 1;
for(position = 1; no_of_ip > position; position++ , clock())
{
if(data_in == 1)
display(position);
}
}
}
void clock(void)
{
CLK = 1;
delay(1);
CLK = 0;
}
void display(unsigned int value)
{
unsigned int a[1];
Beep = 1;
lcd_init();
lcd_cmd(0x01);
string("Pressed key ");
lcd_cmd(0xc0);
sprintf(a,"%d",value);
string(a);
delay(1);
Beep = 0;
}
Download the whle file here
github.
16x2 LCD Interfacing with STM32,STM32F103C6 lcd_init(); LCD_LINE1; lcd_String(" GeElectron"); LCD_LINE2; lc...