Code C - [expand] 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 sbit SH_CP at RD0_bit; sbit SH_CP_Direction at TRISD0_bit; sbit ST_CP at RD2_bit; sbit ST_CP_Direction at TRISD2_bit; sbit DS at RD1_bit; sbit DS_Direction at TRISD1_bit; char uart_rd; unsigned int value2hc595 = 0; void interrupt() { if(RCIF_bit) { if(OERR_bit) { CREN_bit = 0; CREN_bit = 1; OERR_bit = 0; } uart_rd = UART1_Read(); RCIF_bit = 0; } } void SPI_Send(unsigned long s) { unsigned long mask = 0x2000; char i = 0; for(i = 0; i < 16; i++, mask >>= 1) { if(s & mask) DS = 1; else DS = 0; SH_CP = 1; Delay_ms(10); SH_CP = 0; } ST_CP = 1; Delay_ms(10); ST_CP = 0; } void main() { CMCON = 0x07; ADCON1 = 0x87; TRISA = 0xC0; TRISB = 0x00; TRISC = 0x80; TRISD = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; SH_CP_Direction = 0; SH_CP = 0; ST_CP_Direction = 0; ST_CP = 0; DS_Direction = 0; DS = 0; UART1_Init(9615); Delay_ms(200); RCIF_bit = 0; RCIE_bit = 1; PEIE_bit = 1; GIE_bit = 1; while(1) { if(uart_rd) { switch(uart_rd) { case 'a': value2hc595 = 0b10000010000000; break; case 'b': value2hc595 = 0b10100001000000; break; case 'c': value2hc595 = 0b11000000100000; break; case 'd': value2hc595 = 0b11010000010000; break; case 'e': value2hc595 = 0b10010000001000; break; case 'f': value2hc595 = 0b11100000000100; break; case 'g': value2hc595 = 0b11110000000010; break; case 'h': value2hc595 = 0b10110000000001; break; case 'i': value2hc595 = 0b01100011000000; break; case 'j': value2hc595 = 0b01100001100000; break; case 'k': value2hc595 = 0b10001000110000; break; case 'l': value2hc595 = 0b10101000011000; break; case 'm': value2hc595 = 0b11001000001100; break; case 'n': value2hc595 = 0b11011000000110; break; case 'o': value2hc595 = 0b10011000000011; break; case 'p': value2hc595 = 0b11101010000001; break; case 'q': value2hc595 = 0b11111011100000; break; case 'r': value2hc595 = 0b10111001110000; break; case 's': value2hc595 = 0b01101000111000; break; case 't': value2hc595 = 0b01111000011100; break; case 'u': value2hc595 = 0b10001100001110; break; case 'v': value2hc595 = 0b10101100000111; break; case 'w': value2hc595 = 0b01110110000011; break; case 'x': value2hc595 = 0b11001111000001; break; case 'y': value2hc595 = 0b11011111110000; break; case 'z': value2hc595 = 0b10111001111000; break; case '0': value2hc595 = 0b01110000111100; break; case '1': value2hc595 = 0b10000000011110; break; case '2': value2hc595 = 0b10100000001111; break; case '3': value2hc595 = 0b11000010000111; break; case '4': value2hc595 = 0b11010011000011; break; case '5': value2hc595 = 0b10010011100001; break; } SPI_Send(value2hc595); uart_rd = 0; } } }
Sl No Case Binary to shift
1 a 100000 1111111111 11111111111111111111111111 10000000
2 b 101000 1111111111 11111111111111111111111111 01000000
3 c 110000 1111111111 11111111111111111111111111 00100000
4 d 110100 1111111111 11111111111111111111111111 00010000
5 e 100100 1111111111 11111111111111111111111111 00001000
6 f 111000 1111111111 11111111111111111111111111 00000100
7 g 111100 1111111111 11111111111111111111111111 00000010
8 h 101100 1111111111 11111111111111111111111111 00000001
9 i 011000 1111111111 11111111111111111111111111 11000000
10 j 011000 1111111111 11111111111111111111111111 01100000
11 k 100010 1111111111 11111111111111111111111111 00110000
12 l 101010 1111111111 11111111111111111111111111 00011000
13 m 110010 1111111111 11111111111111111111111111 00001100
14 n 110110 1111111111 11111111111111111111111111 00000110
15 o 100110 1111111111 11111111111111111111111111 00000011
16 p 111010 1111111111 11111111111111111111111111 10000001
17 q 111110 1111111111 11111111111111111111111111 11100000
18 r 101110 1111111111 11111111111111111111111111 01110000
19 s 011010 1111111111 11111111111111111111111111 00111000
20 t 011110 1111111111 11111111111111111111111111 00011100
21 u 100011 1111111111 11111111111111111111111111 00001110
22 v 101011 1111111111 11111111111111111111111111 00000111
23 w 011101 1111111111 11111111111111111111111111 10000011
24 x 110011 1111111111 11111111111111111111111111 11000001
25 y 110111 1111111111 11111111111111111111111111 11110000
26 z 101110 1111111111 11111111111111111111111111 01111000
27 0 011100 1111111111 11111111111111111111111111 00111100
28 1 100000 1111111111 11111111111111111111111111 00011110
29 2 101000 1111111111 11111111111111111111111111 00001111
30 3 110000 1111111111 11111111111111111111111111 10000111
31 4 110100 1111111111 11111111111111111111111111 11000011
32 5 100100 1111111111 11111111111111111111111111 11100001
Code C - [expand] 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 sbit SH_CP at RD0_bit; sbit SH_CP_Direction at TRISD0_bit; sbit ST_CP at RD2_bit; sbit ST_CP_Direction at TRISD2_bit; sbit DS at RD1_bit; sbit DS_Direction at TRISD1_bit; char uart_rd; unsigned char value12hc595 = 0, value22hc595 = 0; void interrupt() { if(RCIF_bit) { if(OERR_bit) { CREN_bit = 0; CREN_bit = 1; OERR_bit = 0; } uart_rd = UART1_Read(); RCIF_bit = 0; } } void SPI_Send(unsigned char s1, unsigned char s2) { unsigned long mask; char i = 0; mask = 0x20; for(i = 0; i < 6; i++, mask >>= 1) { if(s1 & mask) DS = 1; else DS = 0; SH_CP = 1; Delay_ms(5); SH_CP = 0; } for(i = 0; i < 36; i++) { DS = 1; SH_CP = 1; Delay_ms(5); SH_CP = 0; } mask = 0x80; for(i = 0; i < 8; i++, mask >>= 1) { if(s2 & mask) DS = 1; else DS = 0; SH_CP = 1; Delay_ms(5); SH_CP = 0; } ST_CP = 1; Delay_ms(5); ST_CP = 0; } void main() { CMCON = 0x07; ADCON1 = 0x87; TRISA = 0xC0; TRISB = 0x00; TRISC = 0x80; TRISD = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; SH_CP_Direction = 0; SH_CP = 0; ST_CP_Direction = 0; ST_CP = 0; DS_Direction = 0; DS = 0; UART1_Init(9615); Delay_ms(200); RCIF_bit = 0; RCIE_bit = 1; PEIE_bit = 1; GIE_bit = 1; while(1) { if(uart_rd) { switch(uart_rd) { case 'a': value12hc595 = 0b100000; value22hc595 = 0b10000000; break; case 'b': value12hc595 = 0b101000; value22hc595 = 0b01000000; break; case 'c': value12hc595 = 0b110000; value22hc595 = 0b00100000; break; case 'd': value12hc595 = 0b110100; value22hc595 = 0b00010000; break; case 'e': value12hc595 = 0b100100; value22hc595 = 0b00001000; break; case 'f': value12hc595 = 0b111000; value22hc595 = 0b00000100; break; case 'g': value12hc595 = 0b111100; value22hc595 = 0b00000010; break; case 'h': value12hc595 = 0b101100; value22hc595 = 0b00000001; break; case 'i': value12hc595 = 0b011000; value22hc595 = 0b11000000; break; case 'j': value12hc595 = 0b011000; value22hc595 = 0b01100000; break; case 'k': value12hc595 = 0b100010; value22hc595 = 0b00110000; break; case 'l': value12hc595 = 0b101010; value22hc595 = 0b00011000; break; case 'm': value12hc595 = 0b110010; value22hc595 = 0b00001100; break; case 'n': value12hc595 = 0b110110; value22hc595 = 0b00000110; break; case 'o': value12hc595 = 0b100110; value22hc595 = 0b00000011; break; case 'p': value12hc595 = 0b111010; value22hc595 = 0b10000001; break; case 'q': value12hc595 = 0b111110; value22hc595 = 0b11100000; break; case 'r': value12hc595 = 0b101110; value22hc595 = 0b01110000; break; case 's': value12hc595 = 0b011010; value22hc595 = 0b00111000; break; case 't': value12hc595 = 0b011110; value22hc595 = 0b00011100; break; case 'u': value12hc595 = 0b100011; value22hc595 = 0b00001110; break; case 'v': value12hc595 = 0b101011; value22hc595 = 0b00000111; break; case 'w': value12hc595 = 0b011101; value22hc595 = 0b10000011; break; case 'x': value12hc595 = 0b110011; value22hc595 = 0b11000001; break; case 'y': value12hc595 = 0b110111; value22hc595 = 0b11110000; break; case 'z': value12hc595 = 0b101110; value22hc595 = 0b01111000; break; case '0': value12hc595 = 0b011100; value22hc595 = 0b00111100; break; case '1': value12hc595 = 0b100000; value22hc595 = 0b00011110; break; case '2': value12hc595 = 0b101000; value22hc595 = 0b00001111; break; case '3': value12hc595 = 0b110000; value22hc595 = 0b10000111; break; case '4': value12hc595 = 0b110100; value22hc595 = 0b11000011; break; case '5': value12hc595 = 0b100100; value22hc595 = 0b11100001; break; } SPI_Send(value12hc595, value22hc595); uart_rd = 0; } } } /*
Sl No Case Binary to shift
1 a 100000 111111111111111111111111111111111111 10000000
2 b 101000 111111111111111111111111111111111111 01000000
3 c 110000 111111111111111111111111111111111111 00100000
4 d 110100 111111111111111111111111111111111111 00010000
5 e 100100 111111111111111111111111111111111111 00001000
6 f 111000 111111111111111111111111111111111111 00000100
7 g 111100 111111111111111111111111111111111111 00000010
8 h 101100 111111111111111111111111111111111111 00000001
9 i 011000 111111111111111111111111111111111111 11000000
10 j 011000 111111111111111111111111111111111111 01100000
11 k 100010 111111111111111111111111111111111111 00110000
12 l 101010 111111111111111111111111111111111111 00011000
13 m 110010 111111111111111111111111111111111111 00001100
14 n 110110 111111111111111111111111111111111111 00000110
15 o 100110 111111111111111111111111111111111111 00000011
16 p 111010 111111111111111111111111111111111111 10000001
17 q 111110 111111111111111111111111111111111111 11100000
18 r 101110 111111111111111111111111111111111111 01110000
19 s 011010 111111111111111111111111111111111111 00111000
20 t 011110 111111111111111111111111111111111111 00011100
21 u 100011 111111111111111111111111111111111111 00001110
22 v 101011 111111111111111111111111111111111111 00000111
23 w 011101 111111111111111111111111111111111111 10000011
24 x 110011 111111111111111111111111111111111111 11000001
25 y 110111 111111111111111111111111111111111111 11110000
26 z 101110 111111111111111111111111111111111111 01111000
27 0 011100 111111111111111111111111111111111111 00111100
28 1 100000 111111111111111111111111111111111111 00011110
29 2 101000 111111111111111111111111111111111111 00001111
30 3 110000 111111111111111111111111111111111111 10000111
31 4 110100 111111111111111111111111111111111111 11000011
32 5 100100 111111111111111111111111111111111111 11100001
Code C - [expand] 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 void SPI_Send(unsigned char s1, unsigned char s2) { unsigned char mask; char i = 0; mask = 0x20; for(i = 0; i < 6; i++, mask >>= 1) { if(s1 & mask) DS = 1; else DS = 0; SH_CP = 1; Delay_ms(5); SH_CP = 0; } DS = 1; for(i = 0; i < 36; i++) { SH_CP = 1; Delay_ms(5); SH_CP = 0; } mask = 0x80; for(i = 0; i < 8; i++, mask >>= 1) { if(s2 & mask) DS = 1; else DS = 0; SH_CP = 1; Delay_ms(5); SH_CP = 0; } ST_CP = 1; Delay_ms(5); ST_CP = 0; }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?