Тёмный

Traffiic lights with LCD and LEDS using ATMEGA32 with PROTEUS 

E TOOLS
Подписаться 64
Просмотров 21
50% 1

Опубликовано:

 

29 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 5   
@EasyElectronics2
@EasyElectronics2 6 месяцев назад
#include #include "LCD.h" #include "timer.h" #define F_CPU 8000000UL #include #include "LED.h" #include volatile unsigned char counter1=0; volatile unsigned char counter_green=10; volatile unsigned char counter_yellow=5; volatile unsigned char counter_red=7; int main(void) { LED_vInit('D',0); LED_vInit('D',1); LED_vInit('D',2); LCD_vInit(); timer_CTC_init_interrupt(); while(1) { counter_green=10; counter_yellow=5; counter_red=7; LCD_clearscreen(); LCD_vSend_string("remaining 10 sec"); LED_vTurnOn('D',0); while(counter_green>0) { if(counter1>=100) { counter1=0; counter_green--; LCD_movecursor(1,11); LCD_vSend_char(' '); LCD_vSend_char((counter_green%10)+48); } } _delay_ms(500); LED_vTurnOn('D',1); LED_vTurnOff('D',0); LCD_clearscreen(); LCD_vSend_string("remaining 5 sec"); while(counter_yellow>0) { if(counter1>=100) { counter1=0; counter_yellow--; LCD_movecursor(1,11); LCD_vSend_char(' '); LCD_vSend_char((counter_yellow%10)+48); } } _delay_ms(500); LED_vTurnOn('D',2); LED_vTurnOff('D',1); LCD_clearscreen(); LCD_vSend_string("remaining 7 sec"); while(counter_red>0) { if(counter1>=100) { counter1=0; counter_red--; LCD_movecursor(1,11); LCD_vSend_char(' '); LCD_vSend_char((counter_red%10)+48); } } _delay_ms(500); LED_vTurnOff('D',2); } } ISR(TIMER0_COMP_vect) { counter1++; }
@EasyElectronics2
@EasyElectronics2 6 месяцев назад
#include #include "std_macros.h" void DIO_vsetPINDir(unsigned char portname,unsigned char pinnumber,unsigned char direction) { switch(portname) { case 'A': if(direction==1) { SET_BIT(DDRA,pinnumber);//Set the direction of the given pin in port A as output } else { CLR_BIT(DDRA,pinnumber);//Set the direction of the given pin in port A as input } break; case 'B': if(direction==1) { SET_BIT(DDRB,pinnumber);//Set the direction of the given pin in port B as output } else { CLR_BIT(DDRB,pinnumber);//Set the direction of the given pin in port B as input } break; case 'C': if(direction==1) { SET_BIT(DDRC,pinnumber);//Set the direction of the given pin in port C as output } else { CLR_BIT(DDRC,pinnumber);//Set the direction of the given pin in port C as input } break; case 'D': if(direction==1) { SET_BIT(DDRD,pinnumber);//Set the direction of the given pin in port D as output } else { CLR_BIT(DDRD,pinnumber);//Set the direction of the given pin in port D as input } break; default: break; } } void DIO_write(unsigned char portname,unsigned char pinnumber,unsigned char outputvalue) { switch(portname) { case 'A' : if(outputvalue==1) { SET_BIT(PORTA,pinnumber);//Set the value of the given pin in port A as High } else { CLR_BIT(PORTA,pinnumber);//Set the value of the given pin in port A as Low } break ; case 'B': if(outputvalue==1) { SET_BIT(PORTB,pinnumber);//Set the value of the given pin in port B as High } else { CLR_BIT(PORTB,pinnumber);//Set the value of the given pin in port B as Low } break ; case 'C' : if(outputvalue==1) { SET_BIT(PORTC,pinnumber);//Set the value of the given pin in port C as High } else { CLR_BIT(PORTC,pinnumber);//Set the value of the given pin in port C as Low } break ; case 'D': if(outputvalue==1) { SET_BIT(PORTD,pinnumber);//Set the value of the given pin in port D as High } else { CLR_BIT(PORTD,pinnumber);//Set the value of the given pin in port D as Low } break ; default: break ; } } unsigned char DIO_u8read(unsigned char portname,unsigned char pinnumber) { unsigned char return_value=0; switch(portname) { case 'A' : return_value=READ_BIT(PINA,pinnumber);//Read the value from the given pin in port A break; case 'B' : return_value=READ_BIT(PINB,pinnumber);//Read the value from the given pin in port B break; case 'C' : return_value=READ_BIT(PINC,pinnumber);//Read the value from the given pin in port C break; case 'D' : return_value=READ_BIT(PIND,pinnumber);//Read the value from the given pin in port D break; default: break; } return return_value ; } void DIO_toggle(unsigned char portname,unsigned char pinnumber) { switch(portname) { case 'A': TOG_BIT(PORTA,pinnumber);//Toggle the value of the given pin in port A break; case 'B': TOG_BIT(PORTB,pinnumber);//Toggle the value of the given pin in port B break; case 'C': TOG_BIT(PORTC,pinnumber);//Toggle the value of the given pin in port C break; case 'D': TOG_BIT(PORTD,pinnumber);//Toggle the value of the given pin in port D break; default: break; } } void DIO_set_port_direction(unsigned char portname,unsigned char direction) { switch(portname) { case 'A' : DDRA=direction; //set the direction of port A break ; case 'B': DDRB=direction; //set the direction of port B break ; case 'C' : DDRC=direction; //set the direction of port C break ; case 'D': DDRD=direction; //set the direction of port D break ; default: break ; } } void DIO_write_port(unsigned char portname,unsigned char portvalue) { switch(portname) { case 'A' : PORTA=portvalue; //Write the given value to the port A break ; case 'B': PORTB=portvalue; //Write the given value to the port B break ; case 'C' : PORTC=portvalue; //Write the given value to the port C break ; case 'D': PORTD=portvalue; //Write the given value to the port D break ; default: break ; } } unsigned char DIO_read_port(unsigned char portname) { unsigned char return_val=0; switch(portname) { case 'A' : return_val=PINA; // read the value of port A break ; case 'B': return_val=PINB; // read the value of port B break ; case 'C' : return_val=PINC; // read the value of port C break ; case 'D': return_val=PIND; // read the value of port D break ; default: break ; } return return_val; } void DIO_vconnectpullup(char portname ,char pinnumber, char connect_pullup) { switch(portname) { case 'A': if(connect_pullup==1) { SET_BIT(PORTA,pinnumber); } else { CLR_BIT(PORTA,pinnumber); } break; case 'B': if(connect_pullup==1) { SET_BIT(PORTB,pinnumber); } else { CLR_BIT(PORTB,pinnumber); } break; case 'C': if(connect_pullup==1) { SET_BIT(PORTC,pinnumber); } else { CLR_BIT(PORTC,pinnumber); } break; case 'D': if(connect_pullup==1) { SET_BIT(PORTD,pinnumber); } else { CLR_BIT(PORTD,pinnumber); } break; } } void write_low_nibble(unsigned char portname,unsigned char value) { value&=0x0f; switch(portname) { case 'A': PORTA&=0xf0; PORTA|=value; case 'B': PORTB&=0xf0; PORTB|=value; case 'C': PORTC&=0xf0; PORTC|=value; case 'D': PORTD&=0xf0; PORTD|=value; } } void write_high_nibble(unsigned char portname,unsigned char value) { value
@EasyElectronics2
@EasyElectronics2 6 месяцев назад
/* * LED.c * * Created: 2/9/2018 7:16:44 PM * Author: Mohamed Zaghlol */ #include "DIO.h" void LED_vInit(unsigned char portname,unsigned char pinnumber) { DIO_vsetPINDir(portname,pinnumber,1);//Set the given pin in the given port as an output } void LED_vTurnOn(unsigned char portname,unsigned char pinnumber) { DIO_write(portname,pinnumber,1);//Set the given pin in the given port to one(on) } void LED_vTurnOff(unsigned char portname,unsigned char pinnumber) { DIO_write(portname,pinnumber,0);//Set the given pin in the given port to zero(off) } void LED_vToggle(unsigned char portname,unsigned char pinnumber) { DIO_toggle(portname,pinnumber);//Set the given pin in the given port to zero if it is one or set it to one if it is zero }
@EasyElectronics2
@EasyElectronics2 6 месяцев назад
/* * LCD.c * * Created: 2/23/2018 4:38:26 PM * Author: Mohamed Zaghlol */ #include "LCD.h" #define F_CPU 8000000UL #include void LCD_vInit(void) { _delay_ms(200); #if defined eight_bits_mode DIO_vsetPINDir('A',0,1); DIO_vsetPINDir('A',1,1); DIO_vsetPINDir('A',2,1); DIO_vsetPINDir('A',3,1); DIO_vsetPINDir('A',4,1); DIO_vsetPINDir('A',5,1); DIO_vsetPINDir('A',6,1); DIO_vsetPINDir('A',7,1); DIO_vsetPINDir('B',EN,1); DIO_vsetPINDir('B',RW,1); DIO_vsetPINDir('B',RS,1); DIO_write('B',RW,0); LCD_vSend_cmd(EIGHT_BITS); //8 bit mode _delay_ms(1); LCD_vSend_cmd(CURSOR_ON_DISPLAN_ON);//display on cursor on _delay_ms(1); LCD_vSend_cmd(CLR_SCREEN);//clear the screen _delay_ms(10); LCD_vSend_cmd(ENTRY_MODE); //entry mode _delay_ms(1); #elif defined four_bits_mode DIO_vsetPINDir('A',4,1); DIO_vsetPINDir('A',5,1); DIO_vsetPINDir('A',6,1); DIO_vsetPINDir('A',7,1); DIO_vsetPINDir('B',EN,1); DIO_vsetPINDir('B',RW,1); DIO_vsetPINDir('B',RS,1); DIO_write('B',RW,0); LCD_vSend_cmd(RETURN_HOME); //return home _delay_ms(10); LCD_vSend_cmd(FOUR_BITS); //4bit mode _delay_ms(1); LCD_vSend_cmd(CURSOR_ON_DISPLAN_ON);//display on cursor on _delay_ms(1); LCD_vSend_cmd(CLR_SCREEN);//clear the screen _delay_ms(10); LCD_vSend_cmd(ENTRY_MODE); //entry mode _delay_ms(1); #endif } static void send_falling_edge(void) { DIO_write('B',EN,1); _delay_ms(2); DIO_write('B',EN,0); _delay_ms(2); } void LCD_vSend_cmd(char cmd) { #if defined eight_bits_mode DIO_write_port('A',cmd); DIO_write('B',RS,0); send_falling_edge(); #elif defined four_bits_mode write_high_nibble('A',cmd>>4); DIO_write('B',RS,0); send_falling_edge(); write_high_nibble('A',cmd); DIO_write('B',RS,0); send_falling_edge(); #endif _delay_ms(1); } void LCD_vSend_char(char data) { #if defined eight_bits_mode DIO_write_port('A',data); DIO_write('B',RS,1); send_falling_edge(); #elif defined four_bits_mode write_high_nibble('A',data>>4); DIO_write('B',RS,1); send_falling_edge(); write_high_nibble('A',data); DIO_write('B',RS,1); send_falling_edge(); #endif _delay_ms(1); } void LCD_vSend_string(char *data) { while((*data)!='\0') { LCD_vSend_char(*data); data++; } } void LCD_clearscreen() { LCD_vSend_cmd(CLR_SCREEN); _delay_ms(10); } void LCD_movecursor(char row,char coloumn) { char data ; if(row>2||row16||coloumn
@EasyElectronics2
@EasyElectronics2 6 месяцев назад
/* * LED.c * * Created: 2/9/2018 7:16:44 PM * Author: Mohamed Zaghlol */ #include "DIO.h" void LED_vInit(unsigned char portname,unsigned char pinnumber) { DIO_vsetPINDir(portname,pinnumber,1);//Set the given pin in the given port as an output } void LED_vTurnOn(unsigned char portname,unsigned char pinnumber) { DIO_write(portname,pinnumber,1);//Set the given pin in the given port to one(on) } void LED_vTurnOff(unsigned char portname,unsigned char pinnumber) { DIO_write(portname,pinnumber,0);//Set the given pin in the given port to zero(off) } void LED_vToggle(unsigned char portname,unsigned char pinnumber) { DIO_toggle(portname,pinnumber);//Set the given pin in the given port to zero if it is one or set it to one if it is zero }