hayawana
Member level 1
- Joined
- Apr 10, 2013
- Messages
- 35
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,524
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 unsigned int conversion1; unsigned char lowbyte; unsigned char highbyte; void main() { int i= 0; /////////Initialization////////////////// ADCON1=0x03; //VSS,VDD, ALL ANi are analog except for AN12 ADCON2=0xAD; //Right justified, 12TAD, 16TOSC TRISA=0xFF; // set trisA as inputs TRISE=0b1111; // set trisE as inputs UART1_Init(9600); // Initialize hardware UART1 and establish communication at 9600 bps Delay_ms(100); // Wait for UART module to stabilize /////////ADC CONVERSION/////////////////// while(1) { for( i=0 ;i<7;i++) { conversion1 = ADC_Read(i); // Read analog value from channel 0 to 6 lowbyte = conversion1; highbyte= conversion1 >> 8; UART1_Write(lowbyte); UART1_Write(highbyte); delay_100ms() ; delay_100ms() ; delay_100ms() ; delay_100ms() ; delay_100ms() ; delay_100ms() ; } } }
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 #define LED1 RD1_bit //LED1 connected to RD1 #define LED2 RD2_bit //LED2 connected to RD2 #define Relay RD0_bit //Relay connected to RD0 #define Buzzer RD6_bit //Buzzer connected to RD6 #define BTSense RD5_bit //assuming GPIO2 of bt is connected to input pin RD5 of uC void main(){ Buzzer = 1; Delay_ms(3000); Buzzer = 0; while(1){ if(BTSense){ LED1 = 1; Relay = 1; } else if(!BTSense){ LED1 = 0; Relay = 0; LED2 = 1; } } }
Code C - [expand] 1 2 3 4 TRISC.F0 = 1; PORTC = 0x00; TRISD = 0x00; PORTD = 0x00;
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 #define LED1 RD1_bit //LED1 connected to RD1 #define LED2 RD2_bit //LED2 connected to RD2 #define Relay RD0_bit //Relay connected to RD0 #define Buzzer PORTD.F7 //Buzzer connected to RD7 #define BTSense RC0_bit //assuming GPIO2 of bluetooth is connected to input pin RC0 of uC unsigned char lowbyte; unsigned char highbyte; ]unsigned int result[7]; void main() { int i= 0; /////////Initialization////////////////// ADCON1=0x03; //VSS,VDD, ALL ANi are analog except for AN12 ADCON2=0xAD; //Right justified, 12TAD, 16TOSC TRISA=0xFF; // set trisA as inputs TRISE=0b1111; // set trisE as inputs TRISD=0x00; TRISC=0b1011000; TRISE=0b111; TRISC = 0x81; PORTC = 0x00; TRISD = 0x00; PORTD = 0x00; Buzzer = 1; Delay_ms(3000); Buzzer = 0; UART1_Init(9600); // Initialize hardware UART1 and establish communication at 9600 bps Delay_ms(100); // Wait for UART module to stabilize while(1){ if(BTSense) { LED1 = 1; Relay = 1; } else if(!BTSense) { LED1 = 0; Relay = 0; LED2 = 1; } for(i=0;i<7;i++) { result[i] = ADC_Read(i); // Read analog value from channel 0 to 6 lowbyte = result[i] & 0x0F; highbyte = result[i] >> 8; UART1_Write(lowbyte); UART1_Write(highbyte); } } }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?