milan.rajik
Banned
Try this. Try the .hex file I have attached. Do not compile. Maybe your compiler is generating wring .hex file. I have compiled for 4 MHz external crystal. Post your exact hardware circuit.
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 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 = 0, i = 0, j = 0; char sequence[12] = {0b11000011, 0b11011011, 0b11100011, 0b11000011, 0b11111011, 0b11100011, 0b11000011, 0b11011011, 0b11100011, 0b11010011, 0b11011011, 0b11110011}; 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(char s) { char mask = 0x80; char i = 0; for(i = 0; i < 8; i++) { if(s & mask) DS = 1; else DS = 0; SH_CP = 1; Delay_ms(2); SH_CP = 0; mask >>= 1; } ST_CP = 1; Delay_ms(2); ST_CP = 0; } void main() { 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 a byte\r\n"); UART1_Write_Text("-----------\r\n\r\n"); RCIE_bit = 1; PEIE_bit = 1;; GIE_bit = 1; while(1) { switch(uart_rd) { case '0': i = 0; break; case '1': i = 3; break; case '2': i = 6; break; case '3': i = 9; break; }; if(uart_rd) { for(j = i; j = (i + 3); j++) { SPI_Send(sequence[i]); Delay_ms(2000); } uart_rd = 0; } } }
Attachments
Last edited: