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