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.

[General] UART switch case shift values

Status
Not open for further replies.

varunme

Advanced Member level 3
Advanced Member level 3
Joined
Aug 10, 2011
Messages
741
Helped
17
Reputation
36
Reaction score
17
Trophy points
1,318
Visit site
Activity points
5,765
I want to send a character from uart and the pic has to recognize it and send a binary to SPI when should be interpreted by a 74hc595 and output in led, but my code is not working, any one can help me?

Code:
int i,vitesse;
char uart_rd;
char HC595_0,HC595_1,HC595_2, ;


void send_data(char HC595_0, char HC595_1, char HC595_2)
{
  SPI1_Write(HC595_0);     // données premier circuit
  SPI1_Write(HC595_1);     // données deuxième circuit
  SPI1_Write(HC595_2);     // données troisième circuit
  PORTD.F6=1;             // impulsion de validation sur LATCH
  PORTD.F6=0;
}
//******************************************************************************
// Programme principal
void main(){

                   
 
  ADCON0=0;                        
  TRISA=1;                          
  TRISB=0;                        
  TRISC=0;                           
  TRISD=0;
  PORTA=0;                        
  PORTB=0;                           
  PORTC=0;                           
  PORTD=0;
  vitesse=0;                        
  i=0;

 
  SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV16,_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW,_SPI_LOW_2_HIGH);

//******************************************************************************
 

  UART1_Init(9600);               // Initialize UART1 module at 9600 bps
  Delay_ms(100);                  // Wait for UART 1module to stabilize
  UART1_Write_Text("Start");
  UART1_Write(13);
  UART1_Write(10);
  while (1) {                     // Endless loop
    if (UART1_Data_Ready()) {
    uart_rd = UART1_Read(); //   read the received data,
    switch (uart_rd )       // If data is received,
    {

    case 1:
    HC595_0=0b00100000;        
    HC595_1=0b00100000;   
    HC595_2=0b00100000;    


    send_data(HC595_0,HC595_1,HC595_2);
    UART1_Write_Text("Done");
    
     break;





    }

     // UART1_Write(uart_rd);       //   and send data via UART1
    }
  }
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top