Search Projects

Final year degree project for engineers DAC0800 based project circuit diagram and interfacing with pic mirocontroller Final year projects based on microcontrollers on programmable peripheral interface 8255
Microcontroller based different projects abstract and source code
PIC 16f877 microcontroller projects Motion control
PIC16f877 motor controller and other light projects
Tutorials of microcontroller PIC16f877, A step by step easy to use self learning rapidex

Sunday, September 18, 2011

PIC18f452 counter MIKROC UP and Down display on LCD

PIC counter with source code written in MIKROC

In this project we will learn how interface an LCD with microcontroller PIC18f452. This is a simple counter project. The project can be used to count any thing like person entering and exiting into a hall or vehicles in a parking.
The input to counter is any thing which can give logic zero when activated like button, infrared receiver, photodiode,LDR, etc.
In the case of button or any other input, the software is writen in such a way that it handles the debouncing effects and remove contineus input counting. Because it remmbers the previous state of the input and compare it each time then decide , the counter shouldbe incremented or decremented or reseted.

Components list:-
1. Microcontroller PIC18f452
2. LCD ( any general purpose 2 line 20 character LCD can be used.)
3. Crystal = 4MHz
4. capacitors (22 pf   2Nos)
5. Push buttons (4 Nos, one for master reset of microcontroller, one for up button, one for down button and one for reset counts)
6. PULLUP resistors (10k ohm 4Nos)

Circuit diagram:-
below is the circuit diagram for UP and Down counter with reset button.

PIC18f452 counter UP and Down display on LCD, programming in mikroc,interface of button, debouncing effect, remove contineous input, IR, check heart beats with LDR,

main features of the counter:-
1. It can be used to counts any thing like person passing through a wake way, cars entering to car parking place,etc.
2. The project has three inputs named UP,DOWN,REST.
3. The program take care the debouncing and contineus input by comparing the current state with previous state of input each time then if these found different then counter is updated by increment of decrement or reset depending upon the input.
4. The major purpose of the project to become familar with the interfacing of LCD with PIC microcontroller PIC18f452.
5. Button interface with microcontroller and its programming.
Coding:-
The program is written in MikroC pro for PIC version 5.0.1, which can be downloaded from mikro.com.
 The code listing are as under:-

// Lcd pinout settings
sbit LCD_RS at RD5_bit;
sbit LCD_EN at RD4_bit;
sbit LCD_D7 at RD3_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D4 at RD0_bit;

// Pin direction
sbit LCD_RS_Direction at TRISD5_bit;
sbit LCD_EN_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD0_bit;
// inputs from buttons
sbit up_counter at RB7_bit;
sbit down_counter at RB6_bit;
sbit reset_counter at RB5_bit;
// functions to perform different tasks
void increment_counts(void);
void decrement_counts(void);
void reset_counts(void);
void print_counts (void);
// Global varaibles
unsigned int my_counts;
unsigned int pre_counts;
bit old_b1;
bit old_b2;
bit old_b3;
char *text = "WELCOME";
char *text1 = "counts = ";

void main() {
Lcd_Init(); // Initialize LCD connected to PORTD

TrisB = 0xE0; // last three PINS as input and other are output. 11100000
PortB = 0xE0;
up_counter = 1;
down_counter = 1;
reset_counter = 1;
my_counts = 0;
pre_counts = 0;
old_b1 = 1;
old_b2 = 1;
old_b3 = 1;
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1, 6, text); // Print text to LCD, 2nd row, 1st column
Lcd_Out(2, 1, text1); // Print text to LCD, 2nd row, 1st column
while(1){
if( up_counter == 0 & & old_b1 == 1) increment_counts();
if( down_counter == 0  & & old_b2 == 1) decrement_counts();
if( reset_counter == 0 & & old_b3 == 1 ) reset_counts();

if(pre_counts != my_counts) print_counts ();
pre_counts = my_counts;
old_b1 = up_counter;
old_b2 = down_counter;
old_b3 = reset_counter;
}
}
void increment_counts(void)
{
my_counts++;
if(my_counts > = 10000) my_counts = 0;
}
void decrement_counts(void)
{
if(my_counts > = 0)my_counts--;

}
void reset_counts(void)
{
my_counts = 0;
}
void print_counts (void)
{
unsigned int temp;
unsigned char lcd_out_char;
lcd_out_char = (my_counts/1000)+48;
temp = my_counts % 1000;
Lcd_Chr(2, 11, lcd_out_char); //print on line 2 at char# 11 the 1000th digit
lcd_out_char = (temp/100)+48;
temp = temp % 100;
Lcd_Chr_Cp(lcd_out_char); //print the 100th digit
lcd_out_char = (temp/10)+48;
Lcd_Chr_Cp(lcd_out_char); //print the 10th digit
lcd_out_char = (temp % 10)+48;
Lcd_Chr_Cp(lcd_out_char); //print the unit digit
}
Tags:-
18f452 icsp schema,18f4550 +usb+mikroc+deux interrupts,data logger mikrobasic 18f4550,fan timer circuit using a cd 4001 applications,hitech seven segment display d 0916,18f4550 pwm tuto,mikroc 12f675,mikroc 18f452,
18f4550 lcd example code in MIKROC ,18f452 LCD example circuit diagram,c program for lcd interface,c programming for controllers,lcd display programming by microc,bpm counter на lcd shematic,pic18f452 + c code

0 comments:

Post a Comment

Hi: This is PICINF.blogspot.com comments section. Here you are requested to write your question or problems in detail. Write the question in such a way that, it have all necessary information, sothat i can understand and reply.If you want to send pictures and codes then e-mail me (rghkk@hotmail.com).Thanks.