Professional Documents
Culture Documents
ΤΕΙ ΑΘΗΝΑΣ - Συνοπτικό C reference (Παράρτημα εξετάσεων)
ΤΕΙ ΑΘΗΝΑΣ - Συνοπτικό C reference (Παράρτημα εξετάσεων)
..: .
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.
. 0 .
Bit1-Bit6:
Bit1-Bit6.
Bit7: (DONE STATUS):
1 A/D
. 0
( 18sec).
1000 0000=0.00V
1111 1111=+4.96 V
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)
A/D (ADCSR)
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)
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