Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

74hc595 16f877a interfacing problems

Status
Not open for further replies.
In this code assign the correct 6 bit and 8 bit MSB and LSB values to vale12send and vale22send variables.


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
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;
          }
     }
}

 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
IN words the below portion is different, it is not dummy values

Code:
     for(i = 0; i < 36; i++) {
           DS = 1;
           
           SH_CP = 1;
           Delay_ms(5);
           SH_CP = 0;
     }
 

Yes you can have as many ascii characters you want.
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
ok, but I have to send a binary when a special character is triggered,
but this portion will output only 0 or 1, it is not comparing with the binary we send
 

In the case of

Code:
29	apple	100000 111010 111010 101011 100100 000000 000000 00011110
30	jocker	011100 100110 111100 100010 100100 101110 000000 00001111
31	honey	101100 100110 110110 100100 110111 000000 000000 10000111
32	eagle	100100 101111 111100 111110 100111 000000 000000 11000011

the portion between the LSB and MSB, is not "all zero" or "all one"
There is some difference in values,

Our previous code write only "all zero" or "all one"

The word processing is not a problem, since i can store in special characters
 

How can we reverse the MSB and LSB? just by doing this?

Code:
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 char mask;
     char i = 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;
     }
     mask = 0x20;


     DS = 1;

     for(i = 0; i < 36; i++) {
           SH_CP = 1;
           Delay_ms(5);
           SH_CP = 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;
     }


     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;
      // SPI_Send(0b000000, 0b00000000);
     UART1_Init(9615);
     Delay_ms(200);
      UART1_Write_Text("send characters");

     RCIF_bit = 0;
     RCIE_bit = 1;
     PEIE_bit = 1;
     GIE_bit = 1;

     while(1) {

          if(uart_rd) {

                  switch(uart_rd) {

                        case 'a':
                             value22hc595 = 0b100000;
                             value12hc595 = 0b10000000;
                             break;
                        case 'b':
                             value22hc595 = 0b101000;
                             value12hc595 = 0b01000000;
                             break;
                        case 'c':
                             value22hc595 = 0b110000;
                             value12hc595 = 0b00100000;
                             break;
                        case 'd':
                             value22hc595 = 0b110100;
                             value12hc595 = 0b00010000;
                             break;
                        case 'e':
                             value22hc595 = 0b100100;
                             value12hc595 = 0b00001000;
                             break;
                        case 'f':
                             value22hc595 = 0b111000;
                             value12hc595 = 0b00000100;
                             break;
                        case 'g':
                             value22hc595 = 0b111100;
                             value12hc595 = 0b00000010;
                             break;
                        case 'h':
                             value22hc595 = 0b101100;
                             value12hc595 = 0b00000001;
                             break;
                        case 'i':
                             value22hc595 = 0b011000;
                             value12hc595 = 0b11000000;
                             break;
                        case 'j':
                             value22hc595 = 0b011000;
                             value12hc595 = 0b01100000;
                             break;
                        case 'k':
                             value22hc595 = 0b100010;
                             value12hc595 = 0b00110000;
                             break;
                        case 'l':
                             value22hc595 = 0b101010;
                             value12hc595 = 0b00011000;
                             break;
                        case 'm':
                             value22hc595 = 0b110010;
                             value12hc595 = 0b00001100;
                             break;
                        case 'n':
                             value22hc595 = 0b110110;
                             value12hc595 = 0b00000110;
                             break;
                        case 'o':
                             value22hc595 = 0b100110;
                             value12hc595 = 0b00000011;
                             break;
                        case 'p':
                             value22hc595 = 0b111010;
                             value12hc595 = 0b10000001;
                             break;
                        case 'q':
                             value22hc595 = 0b111110;
                             value12hc595 = 0b11100000;
                             break;
                        case 'r':
                             value22hc595 = 0b101110;
                             value12hc595 = 0b01110000;
                             break;
                        case 's':
                             value22hc595 = 0b011010;
                             value12hc595 = 0b00111000;
                             break;
                        case 't':
                             value22hc595 = 0b011110;
                             value12hc595 = 0b00011100;
                             break;
                        case 'u':
                             value22hc595 = 0b100011;
                             value12hc595 = 0b00001110;
                             break;
                        case 'v':
                             value22hc595 = 0b101011;
                             value12hc595 = 0b00000111;
                             break;
                        case 'w':
                             value22hc595 = 0b011101;
                             value12hc595 = 0b10000011;
                             break;
                        case 'x':
                             value22hc595 = 0b110011;
                             value12hc595 = 0b11000001;
                             break;
                        case 'y':
                             value22hc595 = 0b110111;
                             value12hc595 = 0b11110000;
                             break;
                        case 'z':
                             value22hc595 = 0b101110;
                             value12hc595 = 0b01111000;
                             break;
                        case '0':
                             value22hc595 = 0b011100;
                             value12hc595 = 0b00111100;
                             break;
                        case '1':
                             value22hc595 = 0b100000;
                             value12hc595 = 0b00011110;
                             break;
                        case '2':
                             value22hc595 = 0b101000;
                             value12hc595 = 0b00001111;
                             break;
                        case '3':
                             value22hc595 = 0b110000;
                             value12hc595 = 0b10000111;
                             break;
                        case '4':
                             value22hc595 = 0b110100;
                             value12hc595 = 0b11000011;
                             break;
                        case '5':
                             value22hc595 = 0b100100;
                             value12hc595 = 0b11100001;
                             break;
                  }

                  SPI_Send(value12hc595, value22hc595);
                  uart_rd = 0;
          }
     }
}

- - - Updated - - -

yes, its like that
 

Then a seperate code has to be written which receives single characters like 'a' like "a\r\n" and words like apple like "apple\r\n". Then instead of switch statement, if else if statements have to be used and code has to be written. The SPI_Send() function has also need to be modified.
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top