Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PARKINK LOT control.. help

Status
Not open for further replies.

omani girl

New Member
my project work in ATTINY26 microcontoller.

I used:

infrared sensor

LCD

motor

the number of parking is 20 . I do the program to write full or not full by increment for enterance car only . but the code of infrared sensor dosen't work correctly when I did the implement. I want the LCD read 'NOT FULL'. if the the numbers of car enter is less than 20 . and read Full when it more or equal 20

please check my code. in increment. I think there is some thing missing


PHP:
#define F_CPU 1000000UL /* crystal frequency in Hz*/
#include <ctype.h>
#include <stdint.h>
#include <stdio.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#define setbit(port, bit) (port) |= (1 << (bit))
#define clearbit(port, bit) (port) &= ~(1 << (bit))

// function for initializing the LCD
void LCD_init()
{
PORTA=0x38; // Function set: 2 Line, 8-bit, 5x7 dots
clearbit(PORTB,5); // clear the RS pin
_delay_ms(45);
setbit(PORTB,6); // set the Enable pin
_delay_ms(45);
clearbit(PORTB,6); // clear the RS pin
_delay_ms(45); // wait until the LCD finished execution
PORTA=0x0F; //Display on, Cursor blinking command
clearbit(PORTB,5);
_delay_ms(45);
setbit(PORTB,6);
_delay_ms(45);
clearbit(PORTB,6);
_delay_ms(45); //wait until the LCD finished execution
PORTA=0x01; // clear LCD
clearbit(PORTB,5);
_delay_ms(45);
setbit(PORTB,6);
_delay_ms(45);
clearbit(PORTB,6);
_delay_ms(45); //wait until the LCD finished execution
PORTA=0x06; // Entry mode, auto increment with no shift
clearbit(PORTB,5);
_delay_ms(45);
setbit(PORTB,6);
_delay_ms(45);
clearbit(PORTB,6);
_delay_ms(45); //wait until the LCD finished execution
}

// function for sending data to the LCD
void LCD_sendata(unsigned char y)
{
// this will place the ASCII equivalent of the argument
// sent by the main program on PORTA  LCD (DB0-DB7) input
// thus the character will be recognized and displayed by the LCD
PORTA=y;
setbit(PORTB,5);
_delay_ms(45);
setbit(PORTB,6);
_delay_ms(45);
clearbit(PORTB,6);
_delay_ms(45); //wait until the LCD finished execution
}
			


int main()
{
unsigned char x, y=0; // 8 bit variables


_delay_ms(45); // wait for the LCD to be ON
_delay_ms(45);
_delay_ms(45);
LCD_init(); // call the LCD initialization function
// NOT FULL will be displayed until the counter is greater
// than the no. parkings (e.g 20)
LCD_sendata('N'); // call function for sending a character to LCD
LCD_sendata('O');
LCD_sendata('T');
LCD_sendata(' ');
LCD_sendata('F');
LCD_sendata('U');
LCD_sendata('L');
LCD_sendata('L');
while(1) // repeat forever
{
x = PINB & 1; // read pins of port B and mask the unusigned bits
if(x==1){ // check the infrared sensor output
y++;
} // increment counter

if(y>=20) // compare the counter with no. of parking
{
PORTA=0x01; // clear LCD before displaying the new string
clearbit(PORTB,5);
_delay_ms(45);
setbit(PORTB,6);
_delay_ms(45);
clearbit(PORTB,6);
_delay_ms(45); //wait until the LCD finished execution
LCD_sendata('F'); // call function for sending a character to LCD
LCD_sendata('U');
LCD_sendata('L');
LCD_sendata('L');
break;

}
}
return 0;
}
 
After a quick chat, the problem appears to be that the check for whether the sensor is on always triggers.

This is either because the hardware is wrong, or because the check for the sensor is inverted.

If you are sure that you are checking the right pin, you might like to try:

Code:
if(x==0){ // check the infrared sensor output
y++;
} // increment counter

But without seeing the circuit, it is impossible to tell.
 
OK so it's actually just a debouncing issue. Should have spotted that first. Try this instead:

Code:
if(x==1){ // check the infrared sensor output
y++;
while(PINB & 1);
} // increment counter
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top