Menu English Ukrainian russian Home

Free technical library for hobbyists and professionals Free technical library


ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING
Free library / Schemes of radio-electronic and electrical devices

Traffic light on ATtiny13 microcontroller. Encyclopedia of radio electronics and electrical engineering

Free technical library

Encyclopedia of radio electronics and electrical engineering / Microcontrollers

Comments on the article Comments on the article

I decided to make a traffic light for my little brother from improvised means.

At hand was MK ATtiny13, a few LEDs and resistors. This MK has a flash program memory of 1kb, but this is enough for us, despite the fact that the program is written in C in CodeVisionAVR.

Here is the source code of the program:

/***************************************************** ****
This program was produced by the
CodeWizardAVR V1.25.2 Beta1 Standard
Automatic Program Generator
© Copyright 1998-2006 Pavel Haiduc, HP InfoTech srl
hpinfotech.com

Project:
version:
Date: 27.07.2007
Author : Paul
Company : Home
Comments:

Chip type: ATtiny13
Clock frequency : 4,800000 MHz
Memory model: Tiny
External SRAM size: 0
Data Stack size: 16
******************************************************* ***/

#include
#include
unsigned char light=1;
unsigned char onf=0;
// Pin change interrupt service routine
interrupt [PCINT0] void pin_change_isr(void)
{
// Place your code here
if(PINB.4!=0)
{
if(svet<4)svet++;
else light=1;
onf=0;
}
if(PINB.3!=0)
{
onf=1;
// PORTB.1=1;PORTB.2=1; PORTB.0=1;
}
delay_ms(200);
}

// Declare your global variables here

void main (void)
{
// Declare your local variables here

// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragmaoptsize+
#endif

// Input/Output Ports initialization
// Port B initialization
// Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=Out
// State5=T State4=T State3=T State2=0 State1=0 State0=0
PORTB=0x00;
DDRB=0x1F;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x00;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;

// External Interrupt(s) initialization
// INT0: Off
// Interrupt on any change on pins PCINT0-5: On
GIMSK=0x20;
MCUCR=0x00;
PCMSK=0x1F;
GIFR=0x20;

// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
ACSR=0x80;
ADCSRB=0x00;

// Global enable interrupts
#asm("sei")
//PORTB.0=1; //gr
//PORTB.1=1; //re
//PORTB.2=1; //ye
while (1)
{
if(onf==0)
{
switch (light)
{
case 1:PORTB.0=1; PORTB.1=0; PORTB.2=0; break;
case 2:PORTB.2=1; PORTB.0=0; PORTB.1=0; break;
case 3:PORTB.1=1; PORTB.0=0; PORTB.2=0; break;
case 4:PORTB.1=1;PORTB.2=1; PORTB.0=0; break;
}

}
if(onf==1)
{
if(svet<4)svet++;
else light=1;

switch (light)
{
case 1:PORTB.0=1; PORTB.1=0; PORTB.2=0; break;
case 2:PORTB.2=1; PORTB.0=0; PORTB.1=0; break;
case 3:PORTB.1=1; PORTB.0=0; PORTB.2=0; break;
case 4:PORTB.1=1;PORTB.2=1; PORTB.0=0; break;
}
delay_ms(1000);
}
};
}


Photos of the finished device:

Traffic light on ATtiny13 microcontroller. Photo of the finished device

Traffic light on ATtiny13 microcontroller. Photo of the finished device

Traffic light on ATtiny13 microcontroller. Traffic light in action

HEX firmware, LAY-file and device diagram you can download here (67 kb).

Watch a video of the traffic light

Author: BATCOH (iupfan sabaka mail period ru); Publication: cxem.net

See other articles Section Microcontrollers.

Read and write useful comments on this article.

<< Back

Latest news of science and technology, new electronics:

Machine for thinning flowers in gardens 02.05.2024

In modern agriculture, technological progress is developing aimed at increasing the efficiency of plant care processes. The innovative Florix flower thinning machine was presented in Italy, designed to optimize the harvesting stage. This tool is equipped with mobile arms, allowing it to be easily adapted to the needs of the garden. The operator can adjust the speed of the thin wires by controlling them from the tractor cab using a joystick. This approach significantly increases the efficiency of the flower thinning process, providing the possibility of individual adjustment to the specific conditions of the garden, as well as the variety and type of fruit grown in it. After testing the Florix machine for two years on various types of fruit, the results were very encouraging. Farmers such as Filiberto Montanari, who has used a Florix machine for several years, have reported a significant reduction in the time and labor required to thin flowers. ... >>

Advanced Infrared Microscope 02.05.2024

Microscopes play an important role in scientific research, allowing scientists to delve into structures and processes invisible to the eye. However, various microscopy methods have their limitations, and among them was the limitation of resolution when using the infrared range. But the latest achievements of Japanese researchers from the University of Tokyo open up new prospects for studying the microworld. Scientists from the University of Tokyo have unveiled a new microscope that will revolutionize the capabilities of infrared microscopy. This advanced instrument allows you to see the internal structures of living bacteria with amazing clarity on the nanometer scale. Typically, mid-infrared microscopes are limited by low resolution, but the latest development from Japanese researchers overcomes these limitations. According to scientists, the developed microscope allows creating images with a resolution of up to 120 nanometers, which is 30 times higher than the resolution of traditional microscopes. ... >>

Air trap for insects 01.05.2024

Agriculture is one of the key sectors of the economy, and pest control is an integral part of this process. A team of scientists from the Indian Council of Agricultural Research-Central Potato Research Institute (ICAR-CPRI), Shimla, has come up with an innovative solution to this problem - a wind-powered insect air trap. This device addresses the shortcomings of traditional pest control methods by providing real-time insect population data. The trap is powered entirely by wind energy, making it an environmentally friendly solution that requires no power. Its unique design allows monitoring of both harmful and beneficial insects, providing a complete overview of the population in any agricultural area. “By assessing target pests at the right time, we can take necessary measures to control both pests and diseases,” says Kapil ... >>

Random news from the Archive

IKEA DIRIGER smart home control center 02.06.2022

The furniture manufacturer has announced a new smart home control center that, together with a new app, will be able to control everything from light bulbs to blinds from its catalog and other brands. The center was named DIRIGERA and supports the Matter smart home device standard, which was previously called Project CHIP.

The DIRIGERA device (from the Swedish word for "to guide") is 2,7 cm high with a diameter of 11,2 cm, which is smaller than the previous TRADFRI model, which was the company's only smart home hub. The new hub is equipped with an Ethernet port and a USB-C connector for power. It also bridges WiFi, Zigbee, and Thread connections, serving as a bridge between different networks that can be used by connected entities in every home.

For now, DIRIGERA and the Home Smart app only support Matter and will be able to interface with all Ikea-built equipment as well as Matter-certified products from other brands.

The smart home hub and app will be released in October this year, according to the company's website. And in the first half of next year, they will also introduce a remote access function, making it easier to access devices. IKEA intends to create its own cloud network to offer its users a remote connection to the home.

IKEA executives told The Verge that the entire furniture and décor catalog will become increasingly smart. In the coming years, the brand's stores will feature speakers or wireless chargers built into lamps, shelves and tables.

Other interesting news:

▪ Simple game improves children's math ability

▪ Beosound Balance wireless speaker

▪ Intercontinental travel of bacteria

▪ Portable projector LG PF1000U

▪ The death button in the Qualcomm Snapdragon 810 processor

News feed of science and technology, new electronics

 

Interesting materials of the Free Technical Library:

▪ section of the site Interesting facts. Selection of articles

▪ article by Richard Feynman. Famous aphorisms

▪ article Where was the first theater? Detailed answer

▪ article Car Sampler Maintenance. Standard instruction on labor protection

▪ article Probe for dialing installation. Encyclopedia of radio electronics and electrical engineering

▪ article Amazing fan. Focus Secret

Leave your comment on this article:

Name:


Email (optional):


A comment:





All languages ​​of this page

Home page | Library | Articles | Website map | Site Reviews

www.diagram.com.ua

www.diagram.com.ua
2000-2024