Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101,...

53
Emtron Technologies Pvt. Ltd. Emtron Technologies Pvt. Ltd. Emtron Technologies Pvt. Ltd. Emtron Technologies Pvt. Ltd. Flat No-101, B3 Wing, 1 st Floor, Divyam Hights, Gilbert Hill, Shreenath Nagar, Andheri –West, Mumbai-58 +91-8080181911 E-mail: [email protected] , www.emtrontech.in Do it yourself Embedded Systems workshop Do it yourself Embedded Systems workshop Do it yourself Embedded Systems workshop Do it yourself Embedded Systems workshop is a short term program that offers the knowledge and exposure about the fastest growing field of embedded applications. This program covers concepts that are essential in understanding the functioning of any embedded environment. Starting from these fundamentals, it goes on to cover more interesting and practical aspects such as system design and interfacing with various I/O devices. The contents of the program are discoursed through some theory sessions as well as interesting and interactive hands on sessions as well. Forty hours of exhaustive hands on training program is designed to build your own embedded controller.

Transcript of Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101,...

Page 1: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

Emtron Technologies Pvt. Ltd.Emtron Technologies Pvt. Ltd.Emtron Technologies Pvt. Ltd.Emtron Technologies Pvt. Ltd. Flat No-101, B3 Wing, 1st Floor, Divyam Hights,

Gilbert Hill, Shreenath Nagar, Andheri –West,

Mumbai-58

+91-8080181911

E-mail: [email protected], www.emtrontech.in

Do it yourself Embedded Systems workshopDo it yourself Embedded Systems workshopDo it yourself Embedded Systems workshopDo it yourself Embedded Systems workshop is a short term program that offers the knowledge and exposure about the

fastest growing field of embedded applications. This program covers concepts that are essential in understanding the

functioning of any embedded environment. Starting from these fundamentals, it goes on to cover more interesting and

practical aspects such as system design and interfacing with various I/O devices. The contents of the program are

discoursed through some theory sessions as well as interesting and interactive hands on sessions as well. Forty hours of

exhaustive hands on training program is designed to build your own embedded controller.

Page 2: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

AVR Board Specifications:

1. ATmega 32 Microcontroller Chip

2. Socket for Flashing , ISP, Regulated Power supply

3. LEDs

4. 4 X4 Switch Matrix, 4x1 KBD connectors

5. Serial Communication Port

6. Relay Interface

7. DC & Stepper Motor driver

8. 16x2 LCD interfacing connector

9. 64x128 Graphic LCD interfacing Connector

10. All ports Connections

11. RTC DS1307

12. Connecting wires

13. Bluetooth, Zigbee Interface

14. Servomotor Interface

15. TFT screen interface

16. Touch Screen Interface

17. Interrupts

Page 3: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

Circuit Design

Page 4: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

Layout Design:

1. Atmega 32

2. MAX232 (UART interface)

3. L293D (DC Motor Driver)

4. DS1307 (Real Time Clock)

5. 16x 2 LCD

6. USB ISP Programmer

7. Keyboard, Sensor, LM 35, Realay, Blue tooth, Zig Bee, Servo, GLCD connectors

Page 5: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

USB asp Installation on Windows The method described here will require machine to restart. Make sure you have write

down the steps before proceeding.

Identify The Problem

The main problem is that Microsoft doesn’t allow us to install drivers which are not

‘digitally signed’ directly (or easily) on Windows Vista and later version (7, 8, and also

8.1). To get around this, we must temporarily disable the signature verification process.

Phase 1: Disable Driver Signature Enforcement

1. Enter “start screen” and open “PC Settings”

2. Choose “Update and recovery” option in the left panel.

3. Choose “Recovery” option in the left panel

4. Click on “Restart now” button, below the “Advanced startup” section then click

“reset” button to begin resetting.

5. Once machine is restarted, we will face several options which we can choose by

pressing F1-F9. Choose F7 for “Disable driver signature enforcement”

Now, the machine will boot with no driver signature enforcement. We can then install the

driver to our machine.

Phase 2: USBasp Driver Installation

Download the driver fro Windows from USBasp (http://www.fischl.de/usbasp/). The latest

version is version 2011-05-28.zip which can be downloaded here. Read the readme first.

Because I use WinAVR version 20100110, i will extract the libusb_0.1.12.1 folder as

D:\libusb_0.1.12.1.

Plug the USBasp in to USB port. Windows will try to recognize the device. It should be

recognized but it lacks of driver so the process is not finish.

Open “Device Manager” on “Control Panel”. Look for Other devices. We have USBasp

device there.

Page 6: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

Right click on it and click on “Update Driver Software…”

Click on “Browse my computer for driver software”.

Type the location of folder “D:\libusb_0.1.12.1″ and then click “Next”.

Windows will give warning as it can’t verify the publisher of the driver. Just ignore it and

select “Install this driver software anyway”

Page 7: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

Let the installation proceed and wait until it finish.

Example Programs:

***************************************************

//Example: 1 LED Blink

***************************************************

#include <mega32.h>

#include <delay.h>

void main(void)

{

PORTB=0x00;

DDRD = 0x80;

while (1)

{

PORTD.7 = 0x1;

delay_ms(500);

PORTD.7 = 0x0;

delay_ms(500);

};

Page 8: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

}

**********************************************************

//Example: 2 LED Blink left to right & Right to Left

*********************************************************

#include<mega32.h>

#include<delay.h>

void main (void)

{

while(1)

{

int i;

int j;

DDRD=0Xff;

i=0xff;

PORTD=0xff;

for(j=0;j<=7;j++)

{

PORTD=i;

i<<=1;

delay_ms(500);

}

for(j=0;j<=7;j++)

{

PORTD=i;

i>>=1;

delay_ms(500);

} } }

**********************************************************

//Example: 3 Read Key Press

**********************************************************

#include <mega32.h>

void main(void)

{

DDRD=0x80;

DDRA=0x00;

Page 9: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

PORTA=0XF0;

while(1)

if(PINA.0==0)

{

PORTD.7=1;

}

else

if(PINA.1==0)

{

PORTD.7=0;

} }

**********************************************************

//Example: 4 Read Key Press display array

**********************************************************

#include <mega32.h>

void main(void)

{

int a[3]={1,0,1};

int i;

DDRD=0x80;

DDRA=0x00;

PORTA=0XF0;

while(1)

{ if(PINA.0==0)

{

PORTD.7=a[0];

}

else if

(PINA.1==0)

{

PORTD.7=a[1];

}

else if

(PINA.2==0)

Page 10: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

{

PORTD.7=a[2];

} }}

**********************************************************

//Example: 5 Stepper motor & DC motor

**********************************************************

#include <mega8535.h>

#include <delay.h>

void main(void)

{

PORTC=0x00;

DDRC=0xf0;

PORTD=0x00;

DDRD=0x80;

PORTD.7=0x1; //Enable

PORTC.4=0x0;

PORTC.5=0x1; //DC Motor

while (1)

{

PORTC=0x10; //Step-1

delay_ms(20);

PORTC=0x20; //Step-2

delay_ms(20);

PORTC=0x40; //Step-3

delay_ms(20);

PORTC=0x80; //Step-4

delay_ms(20);

}}

**********************************************************

//Example: 6 LCD 16x2 Interface

**********************************************************

#asm

.equ __lcd_port=0x18 ;PORTB

#endasm

Page 11: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

#include <mega32.h>

#include <lcd.h>

void main(void)

{

lcd_init(16);

lcd_gotoxy(0,0);

lcd_putsf(" Dr. Y. S. Rao");

while (1);

}

**********************************************************

//Example: 7 LCD 16x2 Display right to left

**********************************************************

#asm

.equ __lcd_port=0x18 ;PORTB

#endasm

#include <mega8535.h>

#include <lcd.h>

#include<delay.h>

void main(void)

{

int i=0;

lcd_init(16);

while(1)

{

for(i=16; i>=0; i--)

{

lcd_clear();

lcd_gotoxy(i,0);

lcd_putsf(" Dr. Y. S. Rao");

delay_ms(250);

Page 12: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

}

};

}

**********************************************************

//Example: 8 LCD 16x2 Display 00 to 99

**********************************************************

#asm

.equ __lcd_port=0x18 ;PORTB

#endasm

#include <mega32.h>

#include <lcd.h>

#include<delay.h>

void main(void)

{

int a,b;

while(1)

{

lcd_init(16);

for(b=48;b<=57;b++)

{

for(a=48;a<=57;a++)

{

if(b>48)

{

lcd_gotoxy(6,0);

lcd_putchar((char)b);

}

lcd_gotoxy(7,0);

Page 13: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

lcd_putchar((char)a);

delay_ms(500);

lcd_clear();

}}}}

***************************************************

//Example: 09 INT-0 interrupt

***************************************************

#include <mega32.h>

interrupt [EXT_INT0] void ext_int0_isr(void)

{

PORTD = PORTD ^ 0x80;

}

void main(void)

{

DDRD=0x80;

// External Interrupt(s) initialization

// INT0: On

// INT0 Mode: Low level

// INT1: Off

// INT2: Off

GICR|=0x40;

MCUCR=0x00;

MCUCSR=0x00;

GIFR=0x40;

#asm("sei")

while(1) ;

}

***************************************************

//Example: 10 INT-0, INT-1 interrupt Priority

***************************************************

#include <mega32.h>

interrupt [EXT_INT1] void ext_int1_isr(void)

Page 14: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

{

PORTD.7=0x1;

}

interrupt [EXT_INT0] void ext_int0_isr(void)

{

PORTD.7 = 0x0;

}

void main(void)

{

DDRD=0x80;

// External Interrupt(s) initialization

// INT0: On

// INT0 Mode: Low level

// INT1: On

// INT1 Mode: Low level

// INT2: Off

GICR|=0xC0;

MCUCR=0x00;

MCUCSR=0x00;

GIFR=0xC0;

#asm("sei")

while(1)

;

}

***********************************************************

//Example: 11 INT-0, INT-1, Timer 0 interrupt Priority

***********************************************************

#include <mega32.h>

unsigned int timecount = 0;

interrupt [TIM0_OVF] void timer0_ovf_isr(void)

Page 15: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

{

TCNT0=6;

if(++timecount == 1000)

{

PORTD = PORTD ^ 0x80;

timecount = 0;

}

}

interrupt [EXT_INT1] void ext_int1_isr(void)

{

PORTD = 0x1;

}

interrupt [EXT_INT0] void ext_int0_isr(void)

{

PORTD = 0x0;

}

void main(void)

{

DDRD=0x80;

// Timer/Counter 0 initialization

// Clock source: System Clock

// Mode: Normal top=FFh

// OC0 output: Disconnected

TCCR0=0x01; // Clock value: 8000.000 kHz

TCNT0=0x00;

OCR0=0x00;

// External Interrupt(s) initialization

// INT0: On

// INT0 Mode: Low level

// INT1: On

// INT1 Mode: Low level

// INT2: Off

GICR|=0xC0;

MCUCR=0x00;

MCUCSR=0x00;

Page 16: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

GIFR=0xC0;

TIMSK=0x01; // Timer(s)/Counter(s) Interrupt(s) initialization

#asm("sei")

while(1) ;

}

***********************************************************

//Example: 12 Timer 1 Input Capture (ICP)

***********************************************************

#include <mega8535.h>

#define pulse_out PORTB

#define icp PIND.6

unsigned char ov_counter; //counter for timer 1 overflow

unsigned int rising_edge,falling_edge; // storage for times

unsigned long pulse_clocks; //storage for actual clock counts in the pulse

interrupt [TIM1_OVF] void timer1_ovf_isr(void) //timer 1

{

ov_counter ++; //increment counter when overflow occurs

}

interrupt[TIM1_CAPT] void tiemr1_capt_isr(void) //timer 1 input

{

if(icp)

{

rising_edge=ICR1L; //save start time for pulse

TCCR1B=TCCR1B & 0xBF; //set to trigger on falling edge next

ov_counter =0; // clear overflow counter for this measurement

}

else{

falling_edge=ICR1L; //save falling edge time

TCCR1B=TCCR1B |0X40; //set rising edge

pulse_clocks=(unsigned long)falling_edge-(unsigned long)rising_edge +(unsigned long)ov_counter*0x10000;

Page 17: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

pulse_out=pulse_clocks/500; //output milliseconds to PORTC

}

}

void main(void)

{

DDRB=0XFF; //set port c for output

TCCR1B=0XC2; //timer 1 input to clock/8

TIMSK=0X24; //unmask timer overflow and capture interrupts

#asm("sei") //enable global interrupt bit

while(1)

; //DO NOTHING

}

****************************************************************

//Example: 13 Timer 1 output compare-A interrupt service routine

****************************************************************

#include <mega8535.h>

interrupt [TIM1_COMPA] void timer1_compa_isr(void)

{

OCR1A=OCR1A+25; //set to next match (toggle) point

}

void main(void)

{

DDRD=0x20; // set OC1A bit for output

TCCR1A=0x40; // set prescaler to clock/8 (1 us clocks)

TCCR1B=0x02; //enable output compare mode to toggle OC1A pin on match

TIMSK=0x10; //unmask output compare match interrupt for register A

#asm("sei") //set global interrupt bit

while(1)

Page 18: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

;// do nothing

}

****************************************************************

//Example: 14 Timer 1 Output Compare PWM

****************************************************************

#include <mega8535.h>

#define PWM_select (PINC &3)

void main(void)

{

unsigned int olddat;

PORTC=0x03; //enable the internal pull-ups for in the input bits

TCCR1A=0x91; //compare A fdor non-inverted PWM and 8 bit resoultion

TCCR1B=0x02; //clock /8 prescaler

while(1)

{

if (PWM_select !=olddat)

{

olddat=PWM_select; // save toggle switch value

{

switch (PWM_select)

{

case 0:

OCR1A=25; //10 %duty cycle desired

break;

case 1:

OCR1A= 51; // 20% duty cycle desired

break;

case 2:

OCR1A= 76; //30 % duty cycle desired

break;

case 3:

Page 19: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

OCR1A=102; // 40% duty cycle desired

break;

}

} }}}

***********************************************************

//Example: 15 Watchdog Timer

***********************************************************

#include <mega8535.h>

void main(void)

{

DDRD=0x00;

DDRB=0x0F;

WDTCR = 0xB; //enable WDT and set to 120 ms timeout

while(1)

{

#asm("wdr") //reset the watchdog timer

if(PIND.2==0) //if true disable the WDT

{

WDTCR = 0x18; //set both WDE and WDTOE

WDTCR = 0x00; // clear WDE

PORTB.1=1;

}

{

PORTB.2=0x1;

} } }

***********************************************************

//Example: 16 UART by Polling display on PC terminal

***********************************************************

Page 20: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

#include <mega8535.h>

#include <stdio.h>

int i;

char a;

void main(void)

{

// Communication Parameters: 8 Data, 1 Stop, No Parity

// USART Receiver: On

// USART Transmitter: On

// USART Mode: Asynchronous

UCSRA=0x00;

UCSRB=0x18;

UCSRC=0x86;

UBRRH=0x00;

UBRRL=0x33; // USART Baud Rate: 9600

printf("Embedded Systems by Dr. Y S Rao");

scanf("%d",&i);

if(i==1)

{

printf("one is entered");

}

while(1)

{

scanf("%c",&a);

switch(a)

{

case 'a':

printf("A is entered");

break;

case 'b':

Page 21: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

printf("B is entered");

break;

}

}}

***********************************************************

//Example: 17 UART FLASH memory and PC terminal display

***********************************************************

#include <mega8535.h>

unsigned char qcntr,sndcntr,ch;

unsigned char queue[70];

flash char * flash msg[3]={"that was a","that was b","that was c"};

interrupt [USART_TXC] void usart_tx_isr(void)

{

if (qcntr != sndcntr) UDR=queue[sndcntr++];

}

void sendmsg (flash char *s)

{

qcntr=0;

sndcntr=1;

queue[qcntr++]=0x0d;

queue[qcntr++]=0x0a;

while (*s)queue[qcntr++]=*s++;

UDR=queue[0];

}

void main(void)

{

// Communication Parameters: 8 Data, 1 Stop, No Parity

// USART Receiver: On

// USART Transmitter: On

// USART Mode: Asynchronous

UCSRA=0x00;

Page 22: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

UCSRB=0x18;

UCSRC=0x86;

UBRRH=0x00;

UBRRL=0x33; // USART Baud Rate: 9600

#asm("sei")

while (1)

{

if (UCSRA & 0x80)

{

ch=UDR;

switch(ch)

{

case 'a':

sendmsg(msg[0]);

break;

case 'b':

sendmsg(msg[1]);

break;

case 'c':

sendmsg(msg[2]);

break;

}}} }

***********************************************************

//Example: 18 UART Flash/RAM and PC terminal display

***********************************************************

#include <mega8535.h>

unsigned char qcntr,sndcntr,ch;

unsigned char queue[70];

flash char * flash msg1[15]={"that was a"};

flash char * flash msg2[15]={"that was b"};

flash char * flash msg3[15]={"that was c"};

Page 23: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

//char msg2[]={"that was b"};

//char msg3[]={"that was neither b nor a"};

flash char * flash msg4[30]={"that was neither b nor a nor c"};

interrupt [USART_TXC] void usart_tx_isr(void)

{

if (qcntr != sndcntr) UDR=queue[sndcntr++];

}

void sendmsg (flash char *s)

{

qcntr=0;

sndcntr=1;

queue[qcntr++]=0x0d;

queue[qcntr++]=0x0a;

while (*s)queue[qcntr++]=*s++;

UDR=queue[0];

}

void main(void)

{

// Communication Parameters: 8 Data, 1 Stop, No Parity

// USART Receiver: On

// USART Transmitter: On

// USART Mode: Asynchronous

UCSRA=0x00;

UCSRB=0x18;

UCSRC=0x86;

UBRRH=0x00;

UBRRL=0x33; // USART Baud Rate: 9600

#asm("sei")

while (1)

{

if (UCSRA & 0x80)

{

ch=UDR;

Page 24: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

switch(ch)

{

case 'a':

sendmsg(msg1[0]);

break;

case 'b':

sendmsg(msg2[0]);

break;

case 'c':

sendmsg(msg3[0]);

break;

default:

sendmsg(msg4[0]);

}}} }

***********************************************************

//Example: 19 UART polling data display string on LCD

***********************************************************

#asm

.equ __lcd_port=0x15

#endasm

#include <mega8535.h>

#include <lcd.h>

#include <stdio.h>

#include <string.h>

#include <DELAY.h>

char *a;

int y;

void main(void)

{

Page 25: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

// Communication Parameters: 8 Data, 1 Stop, No Parity

// USART Receiver: On

// USART Transmitter: On

// USART Mode: Asynchronous

UCSRA=0x00;

UCSRB=0x18;

UCSRC=0x86;

UBRRH=0x00;

UBRRL=0x33; // USART Baud Rate: 9600

lcd_init(16);

lcd_clear();

while (1)

{

lcd_gotoxy(0,1);

gets(a,16);

y=strlen(a);

printf("%d",y);

lcd_puts(a);

}

}

***********************************************************

//Example: 20 UART INTO

***********************************************************

#include <mega8535.h>

flash char s[6]="Dr. Y S Rao";

interrupt [EXT_INT0] void ext_int0_isr(void)

{

Page 26: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

PORTB=PORTB^0x1; //toggle the LSB of port B

putsf("s");

//putsf("Dr. Y S Rao");

}

#include <stdio.h>

void main(void)

{

PORTB=0x00;

DDRB=0x01;

// External Interrupt(s) initialization

// INT0: On

// INT0 Mode: Falling Edge

// INT1: Off

// INT2: Off

GICR|=0x40;

MCUCR=0x02;

MCUCSR=0x00;

GIFR=0x40;

// Communication Parameters: 8 Data, 1 Stop, No Parity

// USART Receiver: Off

// USART Transmitter: On

// USART Mode: Asynchronous

// USART Baud rate: 9600

UCSRA=0x00;

UCSRB=0x08;

UCSRC=0x86;

UBRRH=0x00;

UBRRL=0x33;

// Global enable interrupts

#asm("sei")

Page 27: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

while (1)

;

}

***********************************************************

//Example: 21 ADC data on PORTB

***********************************************************

#include <mega8535.h>

#include <delay.h>

#define ADC_VREF_TYPE 0x00

interrupt [ADC_INT] void adc_isr(void)

{

PORTB=(unsigned char) ~(ADCW>>2);

delay_ms(20);

ADCSRA|=0x40;

}

void main(void)

{

PORTB=0xFF; // all outputs

DDRB=0x00; // all LEDs are initially off

// ADC Clock frequency: 1000.000 kHz

// ADC Voltage Reference: AREF pin

// ADC High Speed Mode: Off

// ADC Auto Trigger Source: None

ADMUX=ADC_VREF_TYPE & 0xff;

ADCSRA=0x8B;

SFIOR&=0xEF;

Page 28: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

ADCSRA|=0x40;

#asm("sei")

while (1);

}

***********************************************************

//Example: 22 ADC peak value on LCD

***********************************************************

#asm

.equ __lcd_port=0x18 ;PORTB

#endasm

#include <lcd.h>

#include <mega32.h>

#include <delay.h>

#include <stdlib.h>

#include <math.h>

#define ADC_VREF_TYPE 0x40

unsigned char s;//to pass analog input value

float peak=0,temp,arr[50];

int i=1;

char lcd_volt[7];

float read_adc(unsigned char adc_input)

{

delay_ms(10);

ADCSRA|=0x40;

while ((ADCSRA & 0x10)==0);

ADCSRA|=0x10;

return ADCW;

}

Page 29: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

void main(void)

{

ADCSRA=0x85;

#asm("sei")

lcd_init(16);

while(1){

lcd_clear();

ADMUX=0x00;

while(i<50)

{

arr[i++]= read_adc(s);

}

for(i=1;i<50;i++)

{

if(arr[i]>peak)

peak=arr[i];

}

ftoa(peak,2,lcd_volt); // Float to character conversion upto 2 decimal places..

lcd_gotoxy(0,0);

lcd_putsf("peak voltage =>>");

lcd_gotoxy(0,1);

lcd_puts(lcd_volt); //lcd_volt is array

delay_ms(200);

i=0;

peak=0;

}

}

***********************************************************

Page 30: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

//Example: 23 ADC data on UART PC Terminal

***********************************************************

#include <mega8535.h>

#include <math.h>

#include <stdio.h>

#include <delay.h>

unsigned int snd;

#define ADC_VREF_TYPE 0x40

int read_adc(unsigned char adc_input)

{

ADMUX=adc_input;

ADCSRA|=0x40;

while ((ADCSRA & 0x10)==0);

ADCSRA|=0x10;

return ADCW;

}

void main(void)

{

char ch;

unsigned char mux;

UCSRA=0x00;

UCSRB=0xD8;

UCSRC=0x86;

UBRRH=0x00;

UBRRL=0x33;

ADCSRA=0x86;

#asm("sei")

while(1)

{

Page 31: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

ch=UDR;

if(ch=='a' || ch=='b')

{

switch(ch)

{

case 'a':

mux=0;

break;

case 'b':

mux=1;

break;

}

snd=read_adc(mux);

printf("-%d",snd);

delay_ms(2000);

}

else

{

ch=' ';

continue;

}}}

***********************************************************

//Example: 24 analog comparator

***********************************************************

#include <mega8535.h>

interrupt [ANA_COMP] void ana_comp_isr(void){

PORTB.1=0; //light the LED

}

void main()

{

Page 32: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

DDRB=0x02; //set bit 1 for output

PORTB=0x02; //start with LED off

ACSR=0x0A; //enable analog comp, interrupt ,falling edge

#asm("sei") // set global interrupt enable bit

while(1)

; //do nothing

}

***********************************************************

//Example: 25 SPI data Transmission

***********************************************************

#include <mega8535.h>

#define SPI_output_data PORTC

#define SPI_input_data PIND

interrupt [SPI_STC] void spi_isr()

{

SPI_output_data=SPDR; //read out new data received

SPDR=SPI_input_data; // load new data to start SPI transmission

}

void main()

{

PORTB=0X40; //PULL UP ON MISO

DDRB=0XB0; //SCLK,MOSI , SS=OUTPUT

DDRC=0XFF; //ALL OP

PORTD=0XFF; //PULL UPS FOR DIP SWITCH

SPCR=0XD0; //ENABLE SPI,AND ITS INTERRUPT

#asm

in r30,spsr //SPI Interrupt enable

in r30,spdr

#endasm

Page 33: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

#asm("sei") //global enable interrupts

SPDR = 0x00; //start SPI communication

while(1)

;

}

***************************************************

//Project: 1 Bluetooth Initialization

***************************************************

DDRD.5=0x1;

PORTD.5=0x0; // Hardware Initialization

delay_ms(1000);

PORTD.5=0x1;

delay_ms(1000);

printf("AT+UARTCONFIG,9600,N,1,0 \r");

printf("ATS10=0 \r");

printf("AT+BTMODE,3 \r");

printf("AT+BTSCAN \r");

***************************************************

// Project: 2 Bluetooth as a master

***************************************************

DDRC.3=0x1; //Reset to Bluetooth

PORTC.3=0x0;

delay_ms(2000);

PORTC.3=0x1;

delay_ms(2000);

Page 34: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

printf("AT+UARTCONFIG,9600,N,1,0 \r");

printf("ATS10=0 \r");

printf("ATD000195091DEE \r"); // Slave ESD Number

delay_ms(2000);

DDRA.0=0x1;

DDRA.2=0X0;

DDRA.6=0X1;

DDRA.7=0X1;

lcd_clear();

lcd_putsf("Started ");

PORTA.6=0X1;

PORTA.7=0X0;

delay_ms(2000);

if (PINA.2==0) //Status Pin

{

PORTA.6=0X0;

PORTA.7=0X1;

lcd_clear();

lcd_putsf("Master sending ");

printf("b");

***************************************************

// Project: 3 Bluetooth as a slave

***************************************************

DDRC.3=0x1; //Reset to Bluetooth

PORTC.3=0x0;

delay_ms(2000);

PORTC.3=0x1;

delay_ms(2000);

printf("AT+UARTCONFIG,9600,N,1,0 \r");

Page 35: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

printf("ATS10=0 \r");

printf("AT+BTMODE,3 \r");

printf("AT+BTSCAN \r");

delay_ms(2000);

DDRA.0=0X1;

DDRA.2=0X0;

DDRA.6=0X1;

DDRA.7=0X1;

lcd_clear();

lcd_putsf("Sl start ");

PORTA.6=0X1;

PORTA.7=0x0;

delay_ms(2000);

if(PINA.2==0)

{

PORTA.6=0X0;

PORTA.7=0X1;

lcd_clear();

lcd_putsf("Sl Receving ");

}

while (1)

{

scanf("%c",&a);

switch(a)

{

case 'a':

lcd_putsf("A is entered");

break;

case 'b':

lcd_putsf("B is entered");

break;

Page 36: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

}

****************************************************

//Project: 4 Program to send a SMS using GSM Modem

****************************************************

#include <mega8535.h>

#asm

.equ __lcd_port=0x15 ;PORTC

#endasm

#include <lcd.h>

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

#include <delay.h>

void main(void)

{

unsigned char a[50],b[50];//,c[16],d[16],e[16],temp1[100], strlength[2], temp2[16];

unsigned char str0[]="AT";

unsigned char str1[]="OK";

unsigned char str2[]={'A','T','+','C','M','G','S','=','"','9','8','2','0','9','6','2','8','7','0','"',';'};

unsigned char str3[]={'Y','S','R','A','O',0x1A};

PORTA=0x00;

DDRA=0x0F;

UCSRA=0x00;

UCSRB=0x18;

UCSRC=0x86;

UBRRH=0x00;

UBRRL=0x33;

lcd_init(16);

Page 37: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

puts(str0); //Cheecking if AT commands are working

putchar(0x0D); //Enter

putchar(0x0A); //Line feed

gets(a,16); //Input from UDR (carriage return)

gets(b,16); //Input from UDR (OK)

delay_ms(1000);

lcd_gotoxy(0,0);

lcd_puts(str0);

lcd_gotoxy(0,1);

lcd_puts(a); //Display the response on LCD

delay_ms(5000);

lcd_gotoxy(0,1);

lcd_puts(b); //Display the response on LCD

delay_ms(5000);

lcd_clear();

if(strncmp(b,str1,2)==0)

{

puts(str2);

putchar(0x0D); //Enter

putchar(0x0A); //Line feed

delay_ms(1000);

puts(str3);

lcd_puts(str3);

};

}

******************************************************

// Project: 5 Program to call a person using GSM

******************************************************

#include <mega8535.h>

Page 38: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

#asm

.equ __lcd_port=0x15 ;PORTC

#endasm

#include <lcd.h>

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

#include <delay.h>

// Declare your global variables here

void main(void)

{

unsigned char a[50];

unsigned char str0[]="AT";

unsigned char str1[]={'a','t','d',' ','9','8','2','0','9','6','2','8','7','0',';','\0'};

PORTA=0x00;

DDRA=0x0F;

UCSRA=0x00;

UCSRB=0x18;

UCSRC=0x86;

UBRRH=0x00;

UBRRL=0x33;

lcd_init(16);

puts(str0); //Cheecking if AT commands are working

putchar(0x0D); //Enter

putchar(0x0A); //Line feed

gets(a,16); //Input from UDR (carriage return)

gets(a,16); //Input from UDR (OK)

Page 39: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

lcd_gotoxy(0,0);

lcd_puts(str0);

lcd_gotoxy(0,1);

lcd_puts(a); //Display the response on LCD

delay_ms(5000);

lcd_clear();

puts(str1);

putchar(0x0D); //Enter

putchar(0x0A); //Line feed

gets(a,50);

gets(a,50);

lcd_gotoxy(0,0);

lcd_puts(str1);

lcd_gotoxy(0,1);

lcd_puts(a); //Display the response on LCD

delay_ms(5000);

}

**************************************************************************

// Project: 6 Program to receive SMS through GSM and compare with string

**************************************************************************

#asm

.equ __lcd_port=0x15

#endasm

#include <mega8535.h>

#include <lcd.h>

#include <stdio.h>

#include <string.h>

Page 40: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

#include <delay.h>

#include <stdlib.h>

void main(void)

{

unsigned char a[16],b[16],c[16],d[16],e[16],temp1[100], strlength[2], temp2[16];

int i,length;

unsigned char str0[] = "AT";

unsigned char str1[]="ATE0"; //Echo off

unsigned char str2[]="OK";

unsigned char str3[]="+CMTI:"; //Indication of new mesg

unsigned char Msg[]="ysrao"; //String

unsigned char str5[]="AT+CMGR=1"; //To read the sms

unsigned char str6[]="AT+CMGF=1"; //To set text mode

unsigned char str7[]="AT+CMGD=1";

for(i=0;i<=100;i++)

{

a[i]=b[i]=c[i]=d[i]=temp1[i]=temp2[i]=0;

}

PORTA=0x00;

DDRA=0x01;

PORTB=0x00;

DDRB=0x00;

PORTC=0x00;

DDRC=0x00;

PORTD=0x00;

DDRD=0x00;

UCSRA=0x00;

UCSRB=0x18;

UCSRC=0x86;

Page 41: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

UBRRH=0x00;

UBRRL=0x33;

lcd_init(16);

while(1)

{

PORTA=0x00;

puts(str0); //Cheecking if AT commands are working

putchar(0x0D); //Enter

putchar(0x0A); //Line feed

gets(a,16); //Input from UDR (carriage return)

gets(a,16); //Input from UDR (OK)

lcd_gotoxy(0,0);

lcd_puts(str0);

lcd_gotoxy(0,1);

lcd_puts(a); //Display the response on LCD

delay_ms(10000);

lcd_clear();

if(strncmp(a,str2,2)==0)

{

lcd_clear();

puts(str1); //Echo off

putchar(0x0D); //Enter

putchar(0x0A); //Line feed

gets(b,16); //Input from UDR (carriage return)

gets(b,16); //Input from UDR (OK)

lcd_gotoxy(0,0);

lcd_puts(str1);

lcd_gotoxy(0,1);

lcd_puts(b); //Display the response on LCD

delay_ms(10000);

lcd_clear();

puts(str6);

putchar(0x0D); //Enter

putchar(0x0A); //Line feed

Page 42: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

gets(d,16);

gets(d,16);

lcd_puts(str6);

lcd_gotoxy(0,1) ;

lcd_puts(d);

delay_ms(10000);

lcd_clear();

while(1)

{

PORTA=0x00;

lcd_clear();

lcd_gotoxy(0,0);

lcd_putsf("Waiting... ");

gets(c,16); //Input from UDR (carriage return)

gets(c,16); //Waiting for the sms

lcd_clear();

lcd_gotoxy(0,1);

delay_ms(1000);

lcd_puts(c);

delay_ms(1000);

lcd_clear();

lcd_gotoxy(0,0);

if(strncmp(c,str3,6)==0)

{

lcd_clear();

puts(str5);

putchar(0x0D); //Enter

gets(e,16);

gets(temp1,100); //Input from UDR (carriage return)

gets(temp2,16); //The Message

lcd_puts(str5);

delay_ms(10000);

lcd_clear();

Page 43: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

lcd_putsf("Reading Message...");

delay_ms(10000);

lcd_clear();

length=strlen(temp2);

itoa(length,strlength);

lcd_puts(strlength);

delay_ms(10000);

lcd_clear();

for(i=0;i<strlen(temp2);i++)

{

lcd_putchar(temp2[i]);

}

delay_ms(5000);

lcd_clear();

if(strncmp(temp2,Msg,strlen(Msg))==0 && strlen(temp2)==(strlen(Msg)+1))

{

PORTA=0x01;

lcd_putsf("Correct message");

delay_ms(1000);

}

else

{

lcd_putsf("wrong message");

delay_ms(1000);

}

puts(str7); //Delete the sms

putchar(0x0D); //Enter

putchar(0x0A); //Line feed

gets(a,16);

gets(a,16);

lcd_clear();

delay_ms(500);

lcd_gotoxy(0,0);

lcd_puts(a);

delay_ms(1000);

Page 44: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

}

}

}

};

}

**********************************************************

// Project: 7 Program to send and receive SMS

**********************************************************

#asm

.equ __lcd_port=0x15

#endasm

#include <mega8535.h>

#include <lcd.h>

#include <stdio.h>

#include <string.h>

#include <delay.h>

#include <stdlib.h>

void main(void)

{

unsigned char a[16],temp1[100], strlength[2], temp2[16];

int i,length;

unsigned char str0[] = "AT";

unsigned char str1[]="ATE0"; //Echo off

unsigned char str2[]="OK";

unsigned char str3[]="+CMTI:"; //Indication of new mesg

unsigned char Msg[]="ysrao"; //String

unsigned char str5[]="AT+CMGR=1"; //To read the sms

unsigned char str6[]="AT+CMGF=1"; //To set text mode

unsigned char str7[]="AT+CMGD=1";

unsigned char str8[]={'A','T','+','C','M','G','S','=','"','9','8','2','0','9','6','2','8','7','0','"',';'};

unsigned char str9[]="LED is on\0";

Page 45: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

unsigned char str10[]="LED is off\0";

for(i=0;i<=100;i++)

{

a[i]=temp1[i]=temp2[i]=0;

}

PORTA=0x00;

DDRA=0x01;

PORTB=0x00;

DDRB=0x00;

PORTC=0x00;

DDRC=0x00;

PORTD=0x00;

DDRD=0x00;

UCSRA=0x00;

UCSRB=0x18;

UCSRC=0x86;

UBRRH=0x00;

UBRRL=0x33;

lcd_init(16);

PORTA=0x00;

puts(str0); //Cheecking if AT commands are working

putchar(0x0D); //Enter

putchar(0x0A); //Line feed

gets(a,16); //Input from UDR (carriage return)

gets(a,16); //Input from UDR (OK)

lcd_gotoxy(0,0);

Page 46: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

lcd_puts(str0);

lcd_gotoxy(0,1);

lcd_puts(a); //Display the response on LCD

delay_ms(10000);

lcd_clear();

if(strncmp(a,str2,2)==0)

{

lcd_clear();

puts(str1); //Echo off

putchar(0x0D); //Enter

putchar(0x0A); //Line feed

gets(a,16); //Input from UDR (carriage return)

gets(a,16); //Input from UDR (OK)

lcd_gotoxy(0,0);

lcd_puts(str1);

lcd_gotoxy(0,1);

lcd_puts(a); //Display the response on LCD

delay_ms(10000);

lcd_clear();

puts(str6);

putchar(0x0D); //Enter

putchar(0x0A); //Line feed

gets(a,16);

gets(a,16);

lcd_puts(str6);

lcd_gotoxy(0,1) ;

lcd_puts(a);

delay_ms(10000);

lcd_clear();

while(1)

{

lcd_clear();

lcd_gotoxy(0,0);

Page 47: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

lcd_putsf("Waiting... ");

gets(a,16); //Input from UDR (carriage return)

gets(a,16); //Waiting for the sms

lcd_clear();

lcd_gotoxy(0,1);

delay_ms(1000);

lcd_puts(a);

delay_ms(1000);

lcd_clear();

lcd_gotoxy(0,0);

if(strncmp(a,str3,6)==0)

{

lcd_clear();

puts(str5);

putchar(0x0D); //Enter

gets(a,16);

gets(temp1,100); //Input from UDR (carriage return)

gets(temp2,16); //The Message

lcd_puts(str5);

delay_ms(10000);

lcd_clear();

lcd_putsf("Reading Message...");

delay_ms(10000);

lcd_clear();

length=strlen(temp2);

itoa(length,strlength);

lcd_puts(strlength);

delay_ms(10000);

lcd_clear();

for(i=0;i<strlen(temp2);i++)

{

lcd_putchar(temp2[i]);

}

delay_ms(5000);

Page 48: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

lcd_clear();

if(strncmp(temp2,Msg,strlen(Msg))==0 && strlen(temp2)==(strlen(Msg)+1))

{

PORTA=0x01;

lcd_putsf("Correct message");

delay_ms(1000);

puts(str8);

putchar(0x0D); //Enter

putchar(0x0A); //Line feed

delay_ms(1000);

puts(str9);

putchar(0x1A);

lcd_clear();

lcd_gotoxy(0,0);

lcd_puts(str8);

lcd_gotoxy(0,1);

lcd_puts(str9);

lcd_clear();

}

else

{

PORTA=0x00;

lcd_putsf("wrong message");

delay_ms(1000);

puts(str8);

putchar(0x0D); //Enter

putchar(0x0A); //Line feed

delay_ms(1000);

puts(str10);

putchar(0x1A);

lcd_clear();

lcd_gotoxy(0,0);

lcd_puts(str8);

Page 49: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

lcd_gotoxy(0,1);

lcd_puts(str10);

lcd_clear();

}

puts(str7); //Delete the sms

putchar(0x0D); //Enter

putchar(0x0A); //Line feed

gets(a,16);

gets(a,16);

lcd_clear();

lcd_gotoxy(0,0);

lcd_puts(a);

delay_ms(1000);

lcd_clear();

} } } }

**********************************************************

// Project: 8 DC Servo Motor Control

**********************************************************

#include <mega88.h>

#include <delay.h>

interrupt [TIM1_COMPA] void timer1_compa_isr(void)

{

PORTD=0xFF;

}

interrupt [TIM1_COMPB] void timer1_compb_isr(void)

{

Page 50: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

PORTD=0x00;

}

void main(void)

{

#pragma optsize-

CLKPR=0x80;

CLKPR=0x00;

#ifdef _OPTIMIZE_SIZE_

#pragma optsize+

#endif

DDRD=0xFF; // Port B data direction configuration as output port.

TCCR1A=0x03; //fast PWM mode prescaller 8

TCCR1B=0x1A;

TCNT1H=0x00; //start count from 00

TCNT1L=0x00;

OCR1AH=0x9c;

OCR1AL=0x40;

OCR1BH=0x07; //0 degrees Initial Position

OCR1BL=0xd0;

TIMSK1=0x06; //Timer(s)/Counter(s) Interrupt(s) initialization

DDRD=0xFF;

#asm("sei")

Page 51: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

while (1)

{

delay_ms(3000);

OCR1BH=0x06; // 45 degree -1

OCR1BL=0x65;

delay_ms(3000);

OCR1BH=0x03; // 90 degree -2

OCR1BL=0xE8;

delay_ms(3000);

OCR1BH=0x07; // 0 degree Initial Position -3

OCR1BL=0xd0;

delay_ms(3000);

};

}

**********************************************************

// Project: 9 DC Servo Motor Control with delay program

**********************************************************

#include <mega88.h>

#include <delay.h>

void main(void)

{

#pragma optsize-

Page 52: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

CLKPR=0x80;

CLKPR=0x00;

#ifdef _OPTIMIZE_SIZE_

#pragma optsize+

#endif

PORTD=0x00;

DDRD.3=0x1;

PORTD.3=0x1;

delay_us(388); //0 degrees

PORTD.3=0x0;

delay_ms(1000);

PORTD.3=0x1;

delay_us(1264); //90 degrees

PORTD.3=0x0;

delay_ms(1000);

PORTD.3=0x1;

delay_us(2140); //180 degrees

PORTD.3=0x0;

delay_ms(1000);

PORTD.3=0x1;

delay_us(1264); //90 degrees

PORTD.3=0x0;

delay_ms(1000);

Page 53: Emtron Technologies Pvt. Ltd.emtrontech.in/kits/avr.pdfEmtron Technologies Pvt. Ltd. Flat No-101, ... Download the driver fro Windows from USBasp ... \libusb_0.1.12.1. Plug the USBasp

while (1)

{

};

}