1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
| #include <built_in.h>
#define UINT16_TO_BINARY_PATTERN_1 "<%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c>"
#define UINT16_TO_BINARY_PATTERN_2 "<%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c>\r\n"
#define UINT16_TO_BINARY(uint16_t) \
(uint16_t & 0x8000 ? '1' : '0'), \
(uint16_t & 0x4000 ? '1' : '0'), \
(uint16_t & 0x2000 ? '1' : '0'), \
(uint16_t & 0x1000 ? '1' : '0'), \
(uint16_t & 0x0800 ? '1' : '0'), \
(uint16_t & 0x0400 ? '1' : '0'), \
(uint16_t & 0x0200 ? '1' : '0'), \
(uint16_t & 0x0100 ? '1' : '0'), \
(uint16_t & 0x0080 ? '1' : '0'), \
(uint16_t & 0x0040 ? '1' : '0'), \
(uint16_t & 0x0020 ? '1' : '0'), \
(uint16_t & 0x0010 ? '1' : '0'), \
(uint16_t & 0x0008 ? '1' : '0'), \
(uint16_t & 0x0004 ? '1' : '0'), \
(uint16_t & 0x0002 ? '1' : '0'), \
(uint16_t & 0x0001 ? '1' : '0')
char txt[128];
unsigned int i = 0;
unsigned int my_16_bit_number = 0;
void main() {
CM1CON0 = 0x00;
CM2CON0 = 0x00;
SLRCON = 0x00;
ANSELA = 0x00;
ANSELB = 0x00;
ANSELC = 0x00;
ANSELD = 0x00;
ANSELE = 0x00;
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x80;
TRISD = 0x00;
TRISE = 0x00;
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
LATA = 0x00;
LATB = 0x00;
LATC = 0x00;
LATD = 0x00;
LATE = 0x00;
UART1_Init(9600);
Delay_ms(100);
UART1_Write_Text("16-bit number rotated number\r");
UART1_Write_Text("-------------------------------\r");
while(1) {
for(i = 0; i < 65536; i++) {
my_16_bit_number = i;
sprintf(txt, UINT16_TO_BINARY_PATTERN_1, UINT16_TO_BINARY(i));
UART1_Write_Text(txt);
my_16_bit_number = (my_16_bit_number << 1) | (my_16_bit_number >> 15);
sprintf(txt, UINT16_TO_BINARY_PATTERN_2, UINT16_TO_BINARY(my_16_bit_number));
UART1_Write_Text(txt);
Delay_ms(1500);
}
}
} |