You are on page 1of 4

:.

..: .

A/D D/A LAB TENDER


PC 16
BASE = 330

I/O.

A/D:
32 16 .
8 bits bit.
50 Hz.
() +5 -5 V.
BASE + 0 control port A/D
. port :

Bit0: ( 1)
( 0).
Bit1-Bit5 ( Bit1-Bit4): 32
( 16
),

bit1-bit5 ( bit1-bit4).

Bit6: 1
. 0
,
bit0.

Bit0: (ERROR STATUS): H 1


. 0 .
Bit1-Bit6:
Bit1-Bit6.
Bit7: (DONE STATUS):
1 A/D
. 0
( 18sec).

H BASE + 1 (DATA PORT). 8bit


A/D . :
00000000= -5.00V

1000 0000=0.00V

1111 1111=+4.96 V

1bit 0.04 Volts.


D/A :
16 .
8 bit +- LSB.
3 sec .
: - 5,00 V + 4,96 V, 20 mV.
BASE+4 D/A .
Bit0-Bit2: D/A 0 1.
Bit3: 1 0 ( 0 - 7). 0 0.
Bit4: 1 1 ( 8 - 15). 0 1.
BASE+5 D/A.
D/A .

1/4

Atmel AVR

9 (include files)
9 (global variables)
9 (functions)
void main(void) {
9 (local variables)
9
9 (/)
(initialization)
9 (Timers - Counter)
9 (External Interrupts)
9 -
9 (UART)
9 .
9 (ADC) .

while (1)
{

}
}

(Data Types)
Bit (Bit Variables)
bit

,

R2 R15.
bit
bit (bit 0) R2,
bit (bit 1) R2 ...
112
bit
.
(Interrupts)
interrupt.
, .
:

/* (external interrupt) */
interrupt [EXT_INT0] void ext_int0_isr(void) {
/* */
}

UART (UCR)

Bit0 (TXB8): 8 bit , CHR9 1.

Bit1 (RXB8): 8 bit , CHR9 1.


Bit2 (CHR9): 9-bit.
Bit3 (TXEN): .
Bit4 (RXEN): .
Bit5 (UDRIE): UART.
Bit6 (TXCIE): .
Bit7 (RXCIE): .
UART (UBRR)
H (baud rate generator) ,
:
Baud Rate = Clock/(16 * (UBRR+1))
clock (system clock).
A/D
A/D (ADMUX)
bits: bit0, bit1, bit2,
bits A/D.
2/4

A/D (ADCSR)

Bit7 (ADEN): ADC.


ADPS2 ADPS1 ADPS0

Bit6 (ADSC): .
0
0
0
2
Bit5 (ADFR): ADC (free run mode).
0
0
1
2
Bit4 (ADIF): 1
0
1
0
4
.
0
1
1
8
Bit3 (ADIE):
1
0
0
16
.
1
0
1
32
Bit2, Bit1, Bit0 (ADPS2, ADPS1, ADPS0):
1
1
0
64
,
1
1
1
128
ADC.
ADC (ADCL, ADCH)
10-bit ADCH (High byte
2 bit ) ADCL (Low byte 8 bit )

(GIMSK)
Bit7: 1 (INT1).
Bit6: 0 (INT0).

(GIFR)
Bit7 (F1):
1 (INT1).
Bit6 (INTF0):
0 (INT0).

(MCUCR)
INT1
INT0 bit3-2 bit1-0,
MCUCR :

Bit3 (Bit1)
0
0
1
1

Bit2 (Bit0)
0
1
0
1


(low level)


(Delay Functions) [delay.h]


void delay_us(unsigned int n): n seconds. n .
void delay_ms(unsigned int n): n milliseconds. n .
(Character Type Functions) [ctype.h]
unsigned char isascii(char c): 1, c ASCII (0...127).
unsigned char iscntrl(char c): 1, c (control
character) (0...31 127).
unsigned char isdigit(char c): 1, c .
unsigned char isspace(char c): 1, c : space, CR HT.
char toascii(char c): ASCII c.
/ (Standard C Input/Output Functions) [stdio.h]
char getchar(void): (UART).
void putchar(char c): c (UART).
void puts(char *str): ( putchar) str,
SRAM, .
void putsf(char flash *str): ( putchar) str,
FLASH, .
void printf(char flash *fmtstr [ , arg1, arg2, ...]):
ANSI C. ,
fmtstr. :
%c:
ASCII
%d:

%i:

%u:

%x:
( )
%X:
( )
%s:
, SRAM
%%:
%
printf ,
fmtstr \.
: \n : , \r :
char *gets(char *str, unsigned char len):
Enter, str.
Enter 0. len.
3/4

len , len ,
0. str.
signed char scanf(char flash *fmtstr [ , arg1 address, arg2 address, ...]):
getchar.
fmtstr.
printf.
(Standard Library Functions) [stdlib.h]
int atoi(char *str): str (int).
long int atol(char *str): str long integer.
void itoa(int n, char *str): n str.
void ltoa(long int n, char *str): long integer n str.
void ftoa(float n, unsigned char decimals, char *str): (float) n
str.
.
void ftoe(float n, unsigned char decimals, char *str): (float) n
str.
. (.. 12.35e-5).
float atof(char *str): str .
int rand (void): - 0 32767.
void srand(int seed): , rand.
(Mathematical Functions) [math.h]
unsigned int abs(int x): x.
unsigned long labs(long int x): long integer x.
int max(int a, int b): a b.
long int lmax(long int a, long int b): long integer a b.
float fmax(float a, float b): a b.
int min(int a, int b): a b.
long int lmin(long int a, long int b): long integer a b.
float fmin(float a, float b): a b.
signed char sign(int x): 1, 0, 1 x , , .
signed char lsign(long int x): 1, 0, 1 long integer x ,
, .
signed char fsign(float x): lsign .
unsigned char isqrt(unsigned int x): x.
unsigned int lsqrt(unsigned long x): isqrt long integer.
float sqrt(float x): x.
float floor(float x): , x.
float ceil(float x): x.
float fmod(float x, float y): : x/y.
float modf(float x, float *ipart): x .
.
ipart.
x
float exp(float x): : e .
float log(float x): x.
float log10(float x): 10, x.
y
float pow(float x, float y): : x .
float sin(float x): x ( ).
float cos(float x): x ( ).
float tan(float x): x ( ).
LCD 2x40 [lcd.h]
void lcd_init(unsigned char lcd_columns): LCD.
(=0 =0).
LCD (.. 20). .
.
void lcd_clear(void): (=0 =0).
void lcd_gotoxy(unsigned char x, unsigned char y): x y.
0.
void lcd_putchar(char c): c .
void lcd_puts(char *str): str, SRAM.
void lcd_putsf(char flash *str): str,
FLASH.

4/4

You might also like