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.
yes, but here its correct binary values,

case 'a':
value12hc595 = 0b100000;
value22hc595 = 0b10000000;
break;
 

Post the binary values. Don't make any more changes. I will not write code again.
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
binary is the same in post #67
 

But output is not the same as the binary, it is somewhat different

That is, according to binary, for 'a' only one in the first block of six leds have to be on (100000), for 'b' only two inthe first block has to be one(101000), for 'c' only two in the first block has to be on (110000)

But in simulation it is
for 'a' all the leds are 'on' in first block and the next block also, some alteration are there.
for 'b' all the leds are 'on' in first block and the next block also, some alteration are there. which is not according to the binary
 

MSB is sent first. Q0 of first 74HC595 will show the LSB. In my Proteus circuit, the topmost 74HC595 shows the LSB.

Code:
1	a	100000 1111111111 11111111111111111111111111 10000000

MSB ---------------------------------------------------------------LSB Q0 of topp HC595)
1 00000 1111111111 11111111111111111111111111 1000000 0

MSB is Qx of bottom 74HC595 in my circuit.
 
Last edited:
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
yes, after going through mosfet it goes wrong, i was checking on the leds not on the 595 outputs

thank you

I have sent a pm for you, kindly check and reply
 

You were sending 1 to turn ON and 0 to turn OFF solenoids ? If yes, then code is right. If it in reverse then just invert the bits in the code.
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
yes, i will check in hardware
 

can we rewrite this code for

Code:
 UART1_Read_Text(output, "m", 255);


?

- - - Updated - - -

That is


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;
char output[7];
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();
           UART1_Read_Text(output, "m", 255);
           RCIF_bit = 0;
     }
}

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

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(output) {

                  switch(output) {

                        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);
                  output = 0;
          }
     }
}

- - - Updated - - -

compiling this gives an error
 

compiling this gives an error
This is completely useless information without telling the error and where it occurs.

UART1_Read_Text() should be never used in an interrupt function, because it's blocking.

Generally. I can't see that the recent questions are related to the thread topic "74hc595 16f877a interfacing problems". A thread shouldn't be maintained as a private blog "all about PIC programming".
 

As mentioned by FvM, UART1_Read_Text() cannot be used inside ISR. When you are sending only one character at a time then why do you want to use UART1_Read_Text(). It is to read strings.

In PM you said binary is different. So, if binary is different then SPI_Send() code have to be changed.
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
How can we read strings through interrupt in uart?

- - - Updated - - -

yes, for binary, i am sending only one character at a time, so its not an issue,
But if we can accept multicharacter from uart then it can extend functionality

- - - Updated - - -

yes, for binary, i am sending only one character at a time, so its not an issue,


But if we can accept multicharacter from uart then it can extend functionality

- - - Updated - - -

modified the code parts, now also some problems

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;
char output[7];
unsigned char value12hc595 = 0, value22hc595 = 0, value23hc595 = 0, value24hc595 = 0, value25hc595 = 0, value26hc595 = 0, value27hc595 = 0;

int i = 0;
int x = 0;
bit flag, flag1;


void interrupt() {
     if(RCIF_bit) {
           if(OERR_bit) {
                 CREN_bit = 0;
                 CREN_bit = 1;

                 OERR_bit = 0;
	flag=1;
           }
             }  }


void SPI_Send2(unsigned char s1, unsigned char s3, unsigned char s4, unsigned char s5, unsigned char s6, unsigned char s7, 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;
     }

     mask = 0x80;

     for(i = 0; i < 8; i++, mask >>= 1) {
           if(s3 & mask)
               DS = 1;
           else
               DS = 0;

           SH_CP = 1;
           Delay_ms(5);
           SH_CP = 0;
     }


     mask = 0x80;

     for(i = 0; i < 8; i++, mask >>= 1) {
           if(s4 & mask)
               DS = 1;
           else
               DS = 0;

           SH_CP = 1;
           Delay_ms(5);
           SH_CP = 0;
     }


     mask = 0x80;

     for(i = 0; i < 8; i++, mask >>= 1) {
           if(s5 & mask)
               DS = 1;
           else
               DS = 0;

           SH_CP = 1;
           Delay_ms(5);
           SH_CP = 0;
     }


     mask = 0x80;

     for(i = 0; i < 8; i++, mask >>= 1) {
           if(s6 & mask)
               DS = 1;
           else
               DS = 0;

           SH_CP = 1;
           Delay_ms(5);
           SH_CP = 0;
     }

 mask = 0x08;

     for(i = 0; i < 4; i++, mask >>= 1) {
           if(s7 & mask)
               DS = 1;
           else
               DS = 0;

           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);
      UART1_Write_Text("send characters");

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

     while(1) {

          if(flag) {        
          char output[7];
                    UART1_Read_Text(output, "m", 255);
                  switch(uart_rd) {

                        case 'a':
                             value12hc595 = 0b100000;
                             value22hc595 = 0b10000000;
                             
                             value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;
                             
                             value27hc595 = 0b1000;
                             
                             break;
                        case 'b':
                             value12hc595 = 0b101000;
                             value22hc595 = 0b01000000;
                             
                             value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'c':
                             value12hc595 = 0b110000;
                             value22hc595 = 0b00100000;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'd':
                             value12hc595 = 0b110100;
                             value22hc595 = 0b00010000;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'e':
                             value12hc595 = 0b100100;
                             value22hc595 = 0b00001000;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'f':
                             value12hc595 = 0b111000;
                             value22hc595 = 0b00000100;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'g':
                             value12hc595 = 0b111100;
                             value22hc595 = 0b00000010;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'h':
                             value12hc595 = 0b101100;
                             value22hc595 = 0b00000001;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'i':
                             value12hc595 = 0b011000;
                             value22hc595 = 0b11000000;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'j':
                             value12hc595 = 0b011000;
                             value22hc595 = 0b01100000;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'k':
                             value12hc595 = 0b100010;
                             value22hc595 = 0b00110000;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'l':
                             value12hc595 = 0b101010;
                             value22hc595 = 0b00011000;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'm':
                             value12hc595 = 0b110010;
                             value22hc595 = 0b00001100;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'n':
                             value12hc595 = 0b110110;
                             value22hc595 = 0b00000110;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'o':
                             value12hc595 = 0b100110;
                             value22hc595 = 0b00000011;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'p':
                             value12hc595 = 0b111010;
                             value22hc595 = 0b10000001;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'q':
                             value12hc595 = 0b111110;
                             value22hc595 = 0b11100000;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'r':
                             value12hc595 = 0b101110;
                             value22hc595 = 0b01110000;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 's':
                             value12hc595 = 0b011010;
                             value22hc595 = 0b00111000;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 't':
                             value12hc595 = 0b011110;
                             value22hc595 = 0b00011100;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'u':
                             value12hc595 = 0b100011;
                             value22hc595 = 0b00001110;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'v':
                             value12hc595 = 0b101011;
                             value22hc595 = 0b00000111;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'w':
                             value12hc595 = 0b011101;
                             value22hc595 = 0b10000011;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'x':
                             value12hc595 = 0b110011;
                             value22hc595 = 0b11000001;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'y':
                             value12hc595 = 0b110111;
                             value22hc595 = 0b11110000;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case 'z':
                             value12hc595 = 0b101110;
                             value22hc595 = 0b01111000;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case '0':
                             value12hc595 = 0b011100;
                             value22hc595 = 0b00111100;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case '1':
                             value12hc595 = 0b100000;
                             value22hc595 = 0b00011110;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case '2':
                             value12hc595 = 0b101000;
                             value22hc595 = 0b00001111;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case '3':
                             value12hc595 = 0b110000;
                             value22hc595 = 0b10000111;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case '4':
                             value12hc595 = 0b110100;
                             value22hc595 = 0b11000011;

                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                        case '5':
                             value12hc595 = 0b100100;
                             value22hc595 = 0b11100001;
                             
                               value23hc595 = 0b10000000;
                             value24hc595 = 0b10000000;
                             value25hc595 = 0b10000000;
                             value26hc595 = 0b10000000;

                             value27hc595 = 0b1000;
                             break;
                  }

                  SPI_Send2(value12hc595, value22hc595, value23hc595, value24hc595,value25hc595, value26hc595,value27hc595);
                  uart_rd = 0;
          }
     }
}
 

Just mention the binary you want to send. Why have you used so many variables ?
 

Here is the binary

Code:
Sl No	Case	Binary to shift
1	a	100000 1111111111 11111111111111111111111111 10000000
2	b	101000 1111111111 11111111111111111111111111 01000000
3	d	110100 1111111111 11111111111111111111111111 00010000
4	e	100100 1111111111 11111111111111111111111111 00001000
5	g	111100 1111111111 11111111111111111111111111 00000010
6	h	101100 1111111111 11111111111111111111111111 00000001
7	i	011000 1111111111 11111111111111111111111111 11000000
8	j	011000 1111111111 11111111111111111111111111 01100000
9	k	100010 1111111111 11111111111111111111111111 00110000
10	l	101010 1111111111 11111111111111111111111111 00011000
11	m	110010 1111111111 11111111111111111111111111 00001100
12	n	110110 1111111111 11111111111111111111111111 00000110
13	o	100110 1111111111 11111111111111111111111111 00000011
14	p	111010 1111111111 11111111111111111111111111 10000001
15	q	111110 1111111111 11111111111111111111111111 11100000
16	w	011101 1111111111 11111111111111111111111111 10000011
17	x	110011 1111111111 11111111111111111111111111 11000001
18	y	110111 1111111111 11111111111111111111111111 11110000
19	z	101110 1111111111 11111111111111111111111111 01111000
20	0	011100 1111111111 11111111111111111111111111 00111100
21	1	100000 1111111111 11111111111111111111111111 00011110
22	2	101000 1111111111 11111111111111111111111111 00001111
23	3	110000 1111111111 11111111111111111111111111 10000111
24	4	110100 1111111111 11111111111111111111111111 11000011
25	5	100100 1111111111 11111111111111111111111111 11100001
26	6	111000 1111111111 11111111111111111111111111 11110000
27	7	111100 1111111111 11111111111111111111111111 01111000
28	8	101100 1111111111 11111111111111111111111111 00111100
29	apple	100000 111010 111010 101010 100100 000000 000000 00011110
30	jocker	011100 100110 110000 100010 100100 101110 000000 00001111
31	honey	101100 100110 110110 100100 110111 000000 000000 10000111
32	eagle	100100 101111 111100 101010 100100 000000 000000 11000011
 

The binary is similar to one you posted earlier. assign msb 6 bits to value12sed and lsb 8 bits to value22send.
 

ok, in betweeen that some values have came, that i have splitted into different variables, in our previous code, we had just put dummy values there
 

milan.rajik said:
varunme said:
can you help me in altering the code?

Yes, I can help but only if you can provide the correct binary sequences.

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;
char output[7];
unsigned char value12hc595 = 0, value22hc595 = 0;
            bit flag;
void interrupt() {
     if(RCIF_bit) {
           if(OERR_bit) {
                 CREN_bit = 0;
                 CREN_bit = 1;

                 OERR_bit = 0;
           }
           //uart_rd = UART1_Read();
           flag=1;
           
           RCIF_bit = 0;
     }
}

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


        mask =      0b100000000000000000000000000000000000;
     for(i = 0; i < 36; i++, mask >>= 1) {
          if(s1 & mask)
               DS = 1;
           else
               DS = 0;

           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;
       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(flag) {
          UART1_Read_Text(output, "m", 255);

                  switch(output[7]) {

                        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;
                             
                             case '!':
                             value12hc595 = 0b100100;
                             value22hc595 = 0b11100001;
                             break;
                             
                             case '@':
                             value12hc595 = 0b100100;
                             value22hc595 = 0b11100001;
                             break;
                             
                             case '#':
                             value12hc595 = 0b100100;
                             value22hc595 = 0b11100001;
                             break;
                             
                             case '%':
                             value12hc595 = 0b100100;
                             value22hc595 = 0b11100001;
                             break;
                             
                             case '%':
                             value12hc595 = 0b100100;
                             value22hc595 = 0b11100001;
                             break;
                  }

                  SPI_Send(value12hc595, value22hc595);
                  //output[] = 0;
          }
     }
}


How can we modify for

Code:
        mask =      0b100000000000000000000000000000000000;
     for(i = 0; i < 36; i++, mask >>= 1) {
          if(s1 & mask)
               DS = 1;
           else
               DS = 0;

           SH_CP = 1;
           Delay_ms(5);
           SH_CP = 0;
     }

what mask should be given?
 

You can't do both like test for character and also for words in switch case. I will write two codes, one for single character and another for words. I will reply in two days. But when you send words like "apple" you have to send a delimiter like "apple\r\n" so that the UART function can detect the end of the received word.
 

ok, but i dont have to test words, can store words in special characters like !, @, # etc like

! for apple
@ for boy
# for cat etc

so that programming will be easy
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top