0% found this document useful (0 votes)
24 views34 pages

Code

Uploaded by

nguynanhtu04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views34 pages

Code

Uploaded by

nguynanhtu04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

BT1 LED ĐƠN

#include <mega32.h>

#include <delay.h>

#define TIME 500

void main(void)

DDRC = 0xff ;

while (1)

PORTC.0 = 0 ; // OFF

delay_ms(TIME) ;

PORTC.0 = 1; // ON

delay_ms(TIME) ;

BT2 LED DICH

#include <mega32.h>

#include <delay.h>

int i;

void main(void)

DDRC = 0xff ;

while (1)

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

PORTC = 0b00000001 ;

PORTC = PORTC << i ;


delay_ms(100) ;

BT3 ĐÈN GIAO THÔNG

#include <mega32.h>

#include <delay.h>

#define X1_D2 0b00001100

#define V1_D2 0b00001010

#define D1_X2 0b00100001

#define D1_V2 0b00010001

void main(void)

DDRC = 0b00111111 ;

PORTC = 0b00000000 ;

while (1)

PORTC = X1_D2 ;

delay_ms(1000) ;

PORTC = V1_D2 ;

delay_ms(1000) ;

PORTC = D1_X2 ;

delay_ms(1000) ;

PORTC = D1_V2 ;

delay_ms(1000) ;

}
BT4.1 LED 7 DOAN

#include <mega32.h>

#include <delay.h>

int i ;

unsigned char LED7_Code[10] = {0b11000000,

0b11111001,

0b10100100,

0b10110000,

0b10011001,

0b10010010,

0b10000010,

0b11111000,

0b10000000,

0b10010000,

};

void main(void)

DDRC = 0xff ;

PORTC = 0xff ;

while (1)

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

PORTC = LED7_Code[i];
delay_ms(500);

BT5 BUTTON LED

void main(void)

DDRC = 0xff ;

PORTC = 0x00 ;

DDRA.0 = 0 ;

PORTA.0= 1 ;

DDRA.7 = 0 ;

PORTA.7 = 1 ;

while (1)

if ( PINA.0==0)

PORTC.0=1;

while ( PINA.0==0);

if ( PINA.7==0)

PORTC.7=1;

while ( PINA.7==0);

}
PORTC = 0x00 ;

BT6 BUTTON LED 7 DOAN

#include <mega32.h>

unsigned char LED7_Code[10] = {0b11000000,

0b11111001,

0b10100100,

0b10110000,

0b10011001,

0b10010010,

0b10000010,

0b11111000,

0b10000000,

0b10010000,

};

int i ;

void main(void)

DDRC = 0xff ;

PORTC = 0x00 ;

DDRA.0 = 0 ;

PORTA.0= 1 ;

DDRA.7 = 0 ;

PORTA.7 = 1 ;
while (1)

if ( PINA.0==0)

PORTC.0=1;

while ( PINA.0==0);

i++ ;

PORTC = LED7_Code[i] ;

if (i==9)

i=0 ;

PORTC = 0x00 ;

BT7.1

/*******************************************************

This program was created by the CodeWizardAVR V3.32

Automatic Program Generator

© Copyright 1998-2017 Pavel Haiduc, HP InfoTech s.r.l.

http://www.hpinfotech.com

Project :

Version :

Date : 10/14/2024

Author :
Company :

Comments:

Chip type : ATmega32

Program type : Application

AVR Core Clock frequency: 8.000000 MHz

Memory model : Small

External RAM size :0

Data Stack size : 512

*******************************************************/

#include <mega32.h>

#include <stdlib.h>

// Alphanumeric LCD functions

#include <alcd.h>

int bien ;

char mystr[10] ;

void main(void)

// Declare your local variables here

// Input/Output Ports initialization

// Port A initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In


DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) |
(0<<DDA0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) |


(0<<PORTA1) | (0<<PORTA0);

// Port B initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) |


(0<<DDB0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) |


(0<<PORTB1) | (0<<PORTB0);

// Port C initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) |


(0<<DDC0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) |


(0<<PORTC1) | (0<<PORTC0);

// Port D initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) |


(0<<DDD0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) |


(0<<PORTD1) | (0<<PORTD0);

// Alphanumeric LCD initialization

// Connections are specified in the


// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:

// RS - PORTC Bit 0

// RD - PORTC Bit 1

// EN - PORTC Bit 2

// D4 - PORTC Bit 4

// D5 - PORTC Bit 5

// D6 - PORTC Bit 6

// D7 - PORTC Bit 7

// Characters/line: 8

lcd_init(8);

lcd_clear() ;

lcd_gotoxy(0,0) ;

bien = 100 ;

itoa (bien,mystr) ;

lcd_puts (mystr) ;

while (1)

// Place your code here

BT7.2

/*******************************************************

This program was created by the CodeWizardAVR V3.32

Automatic Program Generator

© Copyright 1998-2017 Pavel Haiduc, HP InfoTech s.r.l.

http://www.hpinfotech.com
Project :

Version :

Date : 10/14/2024

Author :

Company :

Comments:

Chip type : ATmega32

Program type : Application

AVR Core Clock frequency: 8.000000 MHz

Memory model : Small

External RAM size :0

Data Stack size : 512

*******************************************************/

#include <mega32.h>

#include <stdlib.h>

#include <delay.h>

// Alphanumeric LCD functions

#include <alcd.h>

int bien ;

char mystr[10] ;

int i ;

void main(void)
{

// Declare your local variables here

// Input/Output Ports initialization

// Port A initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) |


(0<<DDA0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) |


(0<<PORTA1) | (0<<PORTA0);

// Port B initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) |


(0<<DDB0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) |


(0<<PORTB1) | (0<<PORTB0);

// Port C initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) |


(0<<DDC0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) |


(0<<PORTC1) | (0<<PORTC0);

// Port D initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In


DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) |
(0<<DDD0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) |


(0<<PORTD1) | (0<<PORTD0);

// Alphanumeric LCD initialization

// Connections are specified in the

// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:

// RS - PORTC Bit 0

// RD - PORTC Bit 1

// EN - PORTC Bit 2

// D4 - PORTC Bit 4

// D5 - PORTC Bit 5

// D6 - PORTC Bit 6

// D7 - PORTC Bit 7

// Characters/line: 8

lcd_init(8);

lcd_clear() ;

lcd_gotoxy(0,0) ;

bien = 100 ;

itoa (bien,mystr) ;

lcd_puts (mystr) ;

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

itoa (i,mystr) ;

lcd_puts(mystr) ;
delay_ms(100) ;

while (1)

// Place your code here

BT7.3

/*******************************************************

This program was created by the CodeWizardAVR V3.32

Automatic Program Generator

© Copyright 1998-2017 Pavel Haiduc, HP InfoTech s.r.l.

http://www.hpinfotech.com

Project :

Version :

Date : 10/14/2024

Author :

Company :

Comments:

Chip type : ATmega32

Program type : Application

AVR Core Clock frequency: 8.000000 MHz

Memory model : Small

External RAM size :0

Data Stack size : 512


*******************************************************/

#include <mega32.h>

#include <stdlib.h>

#include <delay.h>

// Alphanumeric LCD functions

#include <alcd.h>

int bien ;

char mystr[10] ;

int i ;

void main(void)

// Declare your local variables here

// Input/Output Ports initialization

// Port A initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) |


(0<<DDA0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) |


(0<<PORTA1) | (0<<PORTA0);

// Port B initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In


DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) |
(0<<DDB0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) |


(0<<PORTB1) | (0<<PORTB0);

// Port C initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) |


(0<<DDC0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) |


(0<<PORTC1) | (0<<PORTC0);

// Port D initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) |


(0<<DDD0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) |


(0<<PORTD1) | (0<<PORTD0);

// Alphanumeric LCD initialization

// Connections are specified in the

// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:

// RS - PORTC Bit 0

// RD - PORTC Bit 1

// EN - PORTC Bit 2

// D4 - PORTC Bit 4

// D5 - PORTC Bit 5

// D6 - PORTC Bit 6
// D7 - PORTC Bit 7

// Characters/line: 8

lcd_init(8);

lcd_clear() ;

lcd_gotoxy(0,0) ;

bien = 100 ;

itoa (bien,mystr) ;

lcd_puts (mystr) ;

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

lcd_clear() ;

lcd_gotoxy(0,0) ;

itoa (i,mystr) ;

lcd_puts(mystr) ;

delay_ms(100) ;

while (1)

// Place your code here

BT8

/*******************************************************

This program was created by the CodeWizardAVR V3.32

Automatic Program Generator

© Copyright 1998-2017 Pavel Haiduc, HP InfoTech s.r.l.


http://www.hpinfotech.com

Project :

Version :

Date : 10/14/2024

Author :

Company :

Comments:

Chip type : ATmega32

Program type : Application

AVR Core Clock frequency: 8.000000 MHz

Memory model : Small

External RAM size :0

Data Stack size : 512

*******************************************************/

#include <mega32.h>

// Alphanumeric LCD functions

#include <alcd.h>

#include <stdlib.h>

int i ;

char mystr[10] ;

// Declare your global variables here

// External Interrupt 0 service routine


interrupt [EXT_INT0] void ext_int0_isr(void)

i++;

itoa (i,mystr) ;

lcd_puts(mystr) ;

void main(void)

// Declare your local variables here

// Input/Output Ports initialization

// Port A initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) |


(0<<DDA0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) |


(0<<PORTA1) | (0<<PORTA0);

// Port B initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) |


(0<<DDB0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) |


(0<<PORTB1) | (0<<PORTB0);

// Port C initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In


DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) |
(0<<DDC0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) |


(0<<PORTC1) | (0<<PORTC0);

// Port D initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) |


(0<<DDD0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) |


(0<<PORTD1) | (0<<PORTD0);

// External Interrupt(s) initialization

// INT0: On

// INT0 Mode: Falling Edge

// INT1: Off

// INT2: Off

MCUCR=(0<<ISC11) | (0<<ISC10) | (1<<ISC01) | (0<<ISC00);

GICR|=(0<<INT1) | (1<<INT0) | (0<<INT2);

MCUCSR=(0<<ISC2);

GIFR=(0<<INTF1) | (1<<INTF0) | (0<<INTF2);

// Alphanumeric LCD initialization

// Connections are specified in the

// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:

// RS - PORTC Bit 0

// RD - PORTC Bit 1
// EN - PORTC Bit 2

// D4 - PORTC Bit 4

// D5 - PORTC Bit 5

// D6 - PORTC Bit 6

// D7 - PORTC Bit 7

// Characters/line: 16

lcd_init(16);

lcd_clear() ;

lcd_gotoxy(0,0) ;

// Globally enable interrupts

#asm("sei")

while (1)

// Place your code here

BT11

#include <mega32.h>

#include <delay.h>

#include <stdlib.h>

// Alphanumeric LCD functions


#include <alcd.h>

// Declare your global variables here

// Voltage Reference: AREF pin

#define ADC_VREF_TYPE ((0<<REFS1) | (0<<REFS0) | (1<<ADLAR))

int nhietdo ;

char mystr[5] ;

unsigned char read_adc(unsigned char adc_input)

ADMUX=adc_input | ADC_VREF_TYPE;

// Delay needed for the stabilization of the ADC input voltage

delay_us(10);

// Start the AD conversion

ADCSRA|=(1<<ADSC);

// Wait for the AD conversion to complete

while ((ADCSRA & (1<<ADIF))==0);

ADCSRA|=(1<<ADIF);

return ADCH;

void main(void)

DDRA = 0xff;

PORTA = 0xff;
DDRB = 0xff;

PORTB = 0xff;

DDRC = 0xff;

PORTC = 0xff;

DDRC = 0xff;

PORTC = 0xff;

ADMUX=ADC_VREF_TYPE;

ADCSRA=(1<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (0<<ADIE) | (1<<ADPS2) | (0<<ADPS1) |


(0<<ADPS0);

SFIOR=(0<<ADTS2) | (0<<ADTS1) | (0<<ADTS0);

lcd_init(16);

lcd_clear() ;

lcd_gotoxy(0,0) ;

while (1)

lcd_clear() ;

lcd_gotoxy(0,0) ;

nhietdo=read_adc(0)*2 ;

itoa (nhietdo,mystr) ;

lcd_puts(mystr) ;

delay_ms(500) ;
}

BT11.1 Hiện chữ

#include <mega32.h>

#include <delay.h>

#include <stdlib.h>

// Alphanumeric LCD functions

#include <alcd.h>

// Declare your global variables here

// Voltage Reference: AREF pin

#define ADC_VREF_TYPE ((0<<REFS1) | (0<<REFS0) | (1<<ADLAR))

int nhietdo ;

char mystr[5] ;

unsigned char read_adc(unsigned char adc_input)

ADMUX=adc_input | ADC_VREF_TYPE;

// Delay needed for the stabilization of the ADC input voltage

delay_us(10);

// Start the AD conversion

ADCSRA|=(1<<ADSC);
// Wait for the AD conversion to complete

while ((ADCSRA & (1<<ADIF))==0);

ADCSRA|=(1<<ADIF);

return ADCH;

void main(void)

DDRA = 0xff;

PORTA = 0xff;

DDRB = 0xff;

PORTB = 0xff;

DDRC = 0xff;

PORTC = 0xff;

DDRC = 0xff;

PORTC = 0xff;

ADMUX=ADC_VREF_TYPE;

ADCSRA=(1<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (0<<ADIE) | (1<<ADPS2) | (0<<ADPS1) |


(0<<ADPS0);

SFIOR=(0<<ADTS2) | (0<<ADTS1) | (0<<ADTS0);


lcd_init(16);

lcd_clear() ;

lcd_gotoxy(0,0) ;

while (1)

lcd_clear() ;

lcd_gotoxy(0,0) ;

nhietdo=read_adc(0)*2 ;

lcd_putsf(" Nhiet do : ") ;

itoa (nhietdo,mystr) ;

lcd_puts(mystr) ;

delay_ms(500) ;

Bt11.2

#include <mega32.h>

#include <delay.h>

#include <stdlib.h>

// Alphanumeric LCD functions

#include <alcd.h>

// Declare your global variables here


// Voltage Reference: AREF pin

#define ADC_VREF_TYPE ((0<<REFS1) | (0<<REFS0) | (1<<ADLAR))

int nhietdo ;

char mystr[5] ;

unsigned char read_adc(unsigned char adc_input)

ADMUX=adc_input | ADC_VREF_TYPE;

// Delay needed for the stabilization of the ADC input voltage

delay_us(10);

// Start the AD conversion

ADCSRA|=(1<<ADSC);

// Wait for the AD conversion to complete

while ((ADCSRA & (1<<ADIF))==0);

ADCSRA|=(1<<ADIF);

return ADCH;

void main(void)

DDRA = 0xff;

PORTA = 0xff;

DDRB = 0xff;

PORTB = 0xff;
DDRC = 0xff;

PORTC = 0xff;

DDRC = 0xff;

PORTC = 0xff;

ADMUX=ADC_VREF_TYPE;

ADCSRA=(1<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (0<<ADIE) | (1<<ADPS2) | (0<<ADPS1) |


(0<<ADPS0);

SFIOR=(0<<ADTS2) | (0<<ADTS1) | (0<<ADTS0);

lcd_init(16);

lcd_clear() ;

lcd_gotoxy(0,0) ;

while (1)

lcd_clear() ;

lcd_gotoxy(0,0) ;

nhietdo=read_adc(0)*2 ;

lcd_putsf(" Nhiet do : ") ;

itoa (nhietdo,mystr) ;

lcd_puts(mystr) ;

delay_ms(500) ;

while (nhietdo >=50)

{
lcd_clear() ;

lcd_gotoxy(0,0) ;

lcd_putsf(" NGUY HIEM ") ;

nhietdo=read_adc(0)*2 ;

BT8

#include <mega32.h>

#include <delay.h>

#include <stdlib.h>

// Alphanumeric LCD functions

#include <alcd.h>

// Declare your global variables here

// Voltage Reference: AREF pin

#define ADC_VREF_TYPE ((0<<REFS1) | (0<<REFS0) | (1<<ADLAR))

int nhietdo ;

char mystr[5] ;
unsigned char read_adc(unsigned char adc_input)

ADMUX=adc_input | ADC_VREF_TYPE;

// Delay needed for the stabilization of the ADC input voltage

delay_us(10);

// Start the AD conversion

ADCSRA|=(1<<ADSC);

// Wait for the AD conversion to complete

while ((ADCSRA & (1<<ADIF))==0);

ADCSRA|=(1<<ADIF);

return ADCH;

void main(void)

DDRA = 0xff;

PORTA = 0xff;

DDRB = 0xff;

PORTB = 0xff;

DDRC = 0xff;

PORTC = 0xff;

DDRC = 0xff;

PORTC = 0xff;
ADMUX=ADC_VREF_TYPE;

ADCSRA=(1<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (0<<ADIE) | (1<<ADPS2) | (0<<ADPS1) |


(0<<ADPS0);

SFIOR=(0<<ADTS2) | (0<<ADTS1) | (0<<ADTS0);

lcd_init(16);

lcd_clear() ;

lcd_gotoxy(0,0) ;

while (1)

lcd_clear() ;

lcd_gotoxy(0,0) ;

nhietdo=(read_adc(0)*500)/255;

lcd_putsf(" Nhiet do : ") ;

itoa (nhietdo,mystr) ;

lcd_puts(mystr) ;

delay_ms(500) ;

BT10ADCPOT-LIN

#include <mega32.h>

#include <stdlib.h>
#include <delay.h>

// Alphanumeric LCD functions

#include <alcd.h>

// Declare your global variables here

// Voltage Reference: AREF pin

#define ADC_VREF_TYPE ((0<<REFS1) | (0<<REFS0) | (1<<ADLAR))

unsigned char ADC0 ;

char mystr[10] ;

unsigned char read_adc(unsigned char adc_input)

ADMUX=adc_input | ADC_VREF_TYPE;

// Delay needed for the stabilization of the ADC input voltage

delay_us(10);

// Start the AD conversion

ADCSRA|=(1<<ADSC);

// Wait for the AD conversion to complete

while ((ADCSRA & (1<<ADIF))==0);

ADCSRA|=(1<<ADIF);

return ADCH;

void main(void)

{
// Declare your local variables here

// Input/Output Ports initialization

// Port A initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) |


(0<<DDA0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) |


(0<<PORTA1) | (0<<PORTA0);

// Port B initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) |


(0<<DDB0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) |


(0<<PORTB1) | (0<<PORTB0);

// Port C initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) |


(0<<DDC0);

// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) |


(0<<PORTC1) | (0<<PORTC0);

// Port D initialization

// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) |


(0<<DDD0);
// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) |


(0<<PORTD1) | (0<<PORTD0);

// ADC initialization

// ADC Clock frequency: 250.000 kHz

// ADC Voltage Reference: AREF pin

// ADC Auto Trigger Source: ADC Stopped

// Only the 8 most significant bits of

// the AD conversion result are used

ADMUX=ADC_VREF_TYPE;

ADCSRA=(1<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (0<<ADIE) | (1<<ADPS2) | (0<<ADPS1) |


(1<<ADPS0);

SFIOR=(0<<ADTS2) | (0<<ADTS1) | (0<<ADTS0);

// Alphanumeric LCD initialization

// Connections are specified in the

// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:

// RS - PORTC Bit 0

// RD - PORTC Bit 1

// EN - PORTC Bit 2

// D4 - PORTC Bit 4

// D5 - PORTC Bit 5

// D6 - PORTC Bit 6

// D7 - PORTC Bit 7

// Characters/line: 16

lcd_init(16);

lcd_clear() ;
lcd_gotoxy(0,0) ;

while (1)

ADC0 = read_adc(0) ;

lcd_clear() ;

lcd_gotoxy(0,0) ;

itoa (ADC0,mystr) ;

lcd_puts(mystr) ;

You might also like