CODEAVRMAU
CODEAVRMAU
CODEAVRMAU
http://www.hpinfotech.com
Project :
Version :
Date : 12/23/2023
Author : NeVaDa
Company :
Comments:
*****************************************************/
#include <mega16.h>
#include <string.h>
#include <delay.h>
#include <alcd.h>
delay_us(10);
ADCSRA|=0x10;
return ADCW;
PORTB.0 =~ PORTB.0;
#ifndef RXB8
#define RXB8 1
#endif
#ifndef TXB8
#define TXB8 0
#endif
#ifndef UPE
#define UPE 2
#endif
#ifndef DOR
#define DOR 3
#endif
#ifndef FE
#define FE 4
#endif
#ifndef UDRE
#define UDRE 5
#endif
#ifndef RXC
#define RXC 7
#endif
#define RX_BUFFER_SIZE 8
char rx_buffer[RX_BUFFER_SIZE];
#else
#endif
bit rx_buffer_overflow;
char status,data;
status=UCSRA;
data=UDR;
rx_buffer[rx_wr_index++]=data;
if (++rx_counter == 0)
#else
if (++rx_counter == RX_BUFFER_SIZE)
rx_counter=0;
#endif
rx_buffer_overflow=1;
PORTC.0=1;
}else if(data=='B'){
PORTC.0=0;
}else if(data=='C'){
PORTC.1=1;
}else if(data=='D'){
PORTC.1=0;
}else if(data=='E'){
PORTC.2=1;
}else if(data=='F'){
PORTC.2=0;
}else if(data=='G'){
PORTC.3=1;
}else if(data=='H'){
PORTC.3=0;
}else if(data=='I'){
PORTC.4=1;
}else if(data=='J'){
PORTC.4=0;
}else if(data=='K'){
PORTC.5=1;
}else if(data=='L'){
PORTC.5=0;
}else if(data=='M'){
PORTC.6=1;
}else if(data=='N'){
PORTC.6=0;
}else if(data=='O'){
PORTC.7=1;
}else if(data=='P'){
PORTC.7=0;
#ifndef _DEBUG_TERMINAL_IO_
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(void)
char data;
while (rx_counter==0);
data=rx_buffer[rx_rd_index++];
#endif
#asm("cli")
--rx_counter;
#asm("sei")
return data;
#pragma used-
#endif
#define TX_BUFFER_SIZE 8
char tx_buffer[TX_BUFFER_SIZE];
#else
unsigned int tx_wr_index,tx_rd_index,tx_counter;
#endif
if (tx_counter)
--tx_counter;
UDR=tx_buffer[tx_rd_index++];
#endif
#ifndef _DEBUG_TERMINAL_IO_
#define _ALTERNATE_PUTCHAR_
#pragma used+
void putchar(char c)
#asm("cli")
tx_buffer[tx_wr_index++]=c;
#endif
++tx_counter;
}
else
UDR=c;
#asm("sei")
#pragma used-
#endif
#include <stdio.h>
TCNT1H=0xD2;
TCNT1L=0x39;
PORTB.1 =~ PORTB.1;
void main(void)
// Port A initialization
PORTA=0x00;
DDRA=0x00;
// Port B initialization
PORTB=0x00;
DDRB=0x03;
// Port C initialization
PORTC=0x00;
DDRC=0xFF;
// Port D initialization
PORTD=0x00;
DDRD=0x02;
// Timer/Counter 0 initialization
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
TCCR1A=0x00;
TCCR1B=0x05;
TCNT1H=0xD2;
TCNT1L=0x39;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: On
// INT1: Off
// INT2: Off
GICR|=0x40;
MCUCR=0x02;
MCUCSR=0x00;
GIFR=0x40;
TIMSK=0x04;
// USART initialization
// USART Receiver: On
// USART Transmitter: On
UCSRA=0x00;
UCSRB=0xD8;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// RS - PORTA Bit 1
// RD - PORTA Bit 2
// EN - PORTA Bit 3
// D4 - PORTA Bit 4
// D5 - PORTA Bit 5
// D6 - PORTA Bit 6
// D7 - PORTA Bit 7
// Characters/line: 16
lcd_init(16);
#asm("sei")
while (1)
// ADC initialization
// ADC Clock frequency: 1000.000 kHz
ADCSRA=0x83;
ADC=read_adc (0);
VOLT=ADC*5000/1023;
nhietdo=VOLT/10;
hangchuc=nhietdo/10;
hangdvi=nhietdo%10;
lcd_gotoxy(0,0);
lcd_gotoxy(9,0);
lcd_putchar(hangchuc+0x30);
lcd_putchar(hangdvi+0x30);