, SerialInit.
, . , , - . , , , 9600 buad , , , 12- . , XTAL/(8 * 250000) 16 250000 8 . , 0x200, , 0x234. UBBRH , , , -, 8 ( ), UBBRL , 8 .
8 0x0234 0x02, 0x02 0x0234,
0x0234 = 0b0000001000110100 (0b , 0x )
, , C ( ). , , , , .
0b0000001000110100 8 0bxxxxxxxx00000010. Xxes - , C, . , 8 , 8 .
, 0x234 UBRRL - 8 . C 8 0x34 .
, 0x234 0x02 0x34 .
UCSRA = (1 < U2X);
-, , . , U2X, , 5 1 < 5 0x01 0b00000001. , , C 5 . , 5 .
So
0b00000001
add five zeros to visualize
0b0000000100000
then chop five off the left
0b00100000
and we end up with 0x20.
UCSRB .
UCSRC ,
UCsrc= (1 < URSEL) + (1 < UCSZ1) + (1 < UCSZ0);
, , .
UCsrc= (1 < 5) + (1 < 2) + (1 < 4);
UCSRA UCSRB,
one with five zeros shifted in
0b100000
Pad that on the left to make it a full 8 bits
0b00100000
one with 2 zeros and one with 4 zeros
0b100 padded is 0b00000100
0b10000 padded is 0b00010000
, :
0b00100000
0b00000100
0b00010000
0b00110100 = 0x34
.
, add . , , , , , , , , . , URSEL UCSZ1
UCsrc= (1 < URSEL) + (1 < UCSZ1) + (1 < UCSZ0);
UCsrc= (1 < 5) + (1 < 5) + (1 < 4);
you would get
0b00100000
0b00100000
0b00010000
which adds to
0b01010000
when you probably wanted to or them and get
0b00110000
, a , , , , .
, , , , . , , ,
0b0SPPLLLL
SS - 1 = 2 0 = 1
PP - 0b00 = 0b01 = 0b10 =
LLLL - 0b1000 = 8, 0b0111 = 7 ..
, - :
SCONTROL = (0 < 7) | (2 < 4) | (8 < 0);
, :
SCONTROL = (ONESTOPBIT < STOPBITS) | (NOPARITY < PARITYBITS) | (DATABITS8 < DATABITS);
, , -, , ( ).
SWITCH_DDR & = ~ SWITCH_BIT;
SWITCH_PORT | = SWITCH_BIT;
, -- - , 3 - , , - :
ra = SOMEREGISTER;
ra&=~7;
ra|=newnumber&7;
SOMEREGISTER = ra;
ra & = ~ 7
start with
0x0000....0000111
take the ones complement, which is make the zeros ones and ones zeros
0x1111....1111000
, 1- , , 0, --- , , , .
, , ~ 7 0xFFFF... FF8. , :
#define SOMEMASK 0x7
and then use
ra&=~SOMEMASK;
ra|=newvalue&SOMEMASK.
#define SOMEMASKBITS 3
#define SOMEMASK ((1
, 0x7 - . 3.