Professional Documents
Culture Documents
ON
INTRODUCTION TO EMBEDDED
SYSTEM AND
EMBEDDED C
BY :UDIT GUPTA
(1209122092)
Characteristics:
Embedded C
program
Simulation
and
debugging
High-performance 8 bit
Microcontroller
Up to 16 MIPS Throughput at 16 MHz
32 x 8 General Purpose Working
Registers
Six ADC channels in PDIP package
Internal Calibrated Oscillator
PORTx
Output
1
Ex:
DDRB1= 0xff;1//configured as o/p
PORTB = 0xff; //output high
give delay
PORTB = 0x00;//output low
Program:
main()
{
DDRB=0XFF;
while(1)
{
PORTB=0XFF;
_delay_ms(255);
PORTB=0X00;
_delay_ms(255);
}
}
#include<avr/io.h>
#include<util/delay.h>
#define F_CPU 1000000UL
void wait(float x)
{
for(int i=0;i<(int)(x*1302);i++)
_delay_loop_1(0);
}
main()
{
DDRB=0xFF;// PORT B as output port
while(1)
{
PORTB=0b11111111;
wait(.5);
PORTB=0b00000000;
wait(.5);
}
}
#include <avr/io.h>
// includes input/output header file
#include <util/delay.h> // includes delay header file
int main(void)
{
DDRB=0b11111111; //PORTB as output Port connected to motors
DDRC=0b0000000; //PORTC Input port connected to Sensors
int left_sensor=0, right_sensor=0;
while(1) // infinite loop
{
left_sensor=PINC&0b0000001; // mask PC4 bit of Port C
right_sensor=PINC&0b0000010;// mask PC5 bit of Port C
if((left_sensor==0b0000000) && (right_sensor==0b0000000)) //if both sensors "off"
{ PORTB=0b00000000; // stop}
if((left_sensor==0b0000001) && (right_sensor==0b0000010)) //if both sensors "on"
{
PORTB=0b00010010; // move straight
}
if((left_sensor==0b0000000)&&(right_sensor==0b0000010))
{
PORTB=0b00000010; // turn left
}
if((left_sensor==0b0000001)&&(right_sensor==0b0000000))
{
PORTB=0b00010000; // turn right
}
}
}