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
unsigned char lowbyte;
unsigned char highbyte;
unsigned char medbyte;
unsigned int conversion1 ;
unsigned int TAB[24][7];
unsigned int conversion[12];
void main()
{
int i= 0;
/////////Initialization//////////////////
ADCON1=0x03; //VSS,VDD, ALL ANi are analog except for AN12
ADCON0=0x01; //select AN0
ADCON0=0x05; //select AN1
ADCON0=0x09; //select AN2
ADCON0=0x0D; //select AN3
ADCON0=0x11; //select AN4
ADCON0=0x15; //select AN5
ADCON0=0x19; //select AN6
ADCON2=0xAD; //Right justified, 12TAD, 16TOSC
TRISA=0xFF; // set trisA as inputs
TRISE=0b1111; // set trisE as inputs
ADON_bit=1; // enable conversion
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++)
{
conversion[12] = ADC_Read(i); // Read analog value from channel 0 to 6
if( i == 0 || i == 5 || i == 6)
TAB[24][i]= conversion[12]*4;
if( i == 3|| i == 4 )
TAB[24][i]= conversion[12]*30;
if( i ==1 || i == 2 )
TAB[24][i]= conversion[12];
lowbyte= TAB[24][i]>>16;
medbyte = TAB[24][i]>> 8;
highbyte= TAB[24][i];
UART1_Write(lowbyte);
UART1_Write(medbyte);
UART1_Write(highbyte);
delay_100ms() ;
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 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; 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 if((i == 0) || ( i == 5) || (i == 6))result[i] = result[i] * 4; elseif((i == 3) || ( i == 4))result[i] = result[i] * 50; lowbyte = result[i] & 0x0F; highbyte = result[i] >> 8; UART1_Write(lowbyte); UART1_Write(highbyte); } } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 for(i=0;i<7;i++) { result[i] = ADC_Read(i); // Read analog value from channel 0 to 6 if((i == 0) || ( i == 5) || (i == 6))result[i] = result[i] * 4; else if((i == 3) || ( i == 4))result[i] = result[i] * 50; lowbyte = result[i] & 0x000000FF;; highbyte = result[i] >> 8; higherbyte = (result[i] & 0x00FF0000) >> 16; highestbyte = (result[i] & 0xFF000000) >> 24; UART1_Write(lowbyte); UART1_Write(highbyte); UART1_Write(higherbyte); UART1_Write(highestbyte); Delay_ms(1000); }
operator is not applicable to these operations
lowbyte = result[i];
highbyte = result[i] >> 8;
unsigned char lowbyte;
unsigned char highbyte;
unsigned char medbyte;
//unsigned int TAB[24][7];
unsigned long TAB[7]; // table for 7 values (32 bits)
//unsigned int conversion[12];
unsigned int conversion; // integer 16 bits , enough for receiving ADC 12 bits long
void main()
{
int i= 0;
/////////Initialization//////////////////
ADCON1=0x03; //VSS,VDD, ALL ANi are analog except for AN12
ADCON0=0x01; //select AN0
ADCON0=0x05; //select AN1
ADCON0=0x09; //select AN2
ADCON0=0x0D; //select AN3
ADCON0=0x11; //select AN4
ADCON0=0x15; //select AN5
ADCON0=0x19; //select AN6
ADCON2=0xAD; //Right justified, 12TAD, 16TOSC
TRISA=0xFF; // set trisA as inputs
TRISE=0b1111; // set trisE as inputs
ADON_bit=1; // enable conversion
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++)
{
conversion = ADC_Read(i); // Read analog value from channel 0 to 6
if( i == 0 || i == 5 || i == 6)
TAB[i]= (long) conversion *4;
if( i == 3|| i == 4 )
TAB[i]= (long) conversion*50;
if( i ==1 || i == 2 )
TAB[i]=(long) conversion;
lowbyte= (unsigned char)(TAB[i] & 0x000000FF);
medbyte = (unsigned char) ((TAB[i]>> 8) & 0x000000FF);
highbyte= (unsigned char) ((TAB[i] >> 16) & 0x000000FF);
UART1_Write(lowbyte);
UART1_Write(medbyte);
UART1_Write(highbyte);
delay_100ms() ;
delay_100ms() ;
delay_100ms() ;
delay_100ms() ;
delay_100ms() ;
delay_100ms() ;
delay_100ms() ;
}
}
}
void main()
{
/////////Initialization//////////////////
TRISC=0b1011000;
UART1_Init(9600); // Initialize hardware UART1 and establish communication at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
////////Configuration////////////////////
UART1_Write_Text("$$$");
DELAY_MS(500);
UART_Write_Text("SU,9600"); // Change the baudrate to 9600
UART1_Write(0x09); // new line NL
UART1_Write(0x0d); // enter CR
UART_Write_Text("R,1"); // Reboot
UART1_Write(0x09); // new line NL
UART1_Write(0x0d); // enter CR
UART1_Write_Text("$$$");
DELAY_MS(500);
UART1_Write(0x09); // new line NL
UART1_Write(0x0d); // enter CR
UART_Write_Text("SM,0"); // Slave mode
DELAY_MS(500);
UART1_Write(0x09); // new line NL
UART1_Write(0x0d); // enter CR
UART_Write_Text("SA,4"); // Authentification Pin code mode
DELAY_MS(500);
UART1_Write(0x09); // new line NL
UART1_Write(0x0d); // enter CR
UART_Write_Text("SP,0000"); // Set Pin code to 0000
DELAY_MS(500);
UART1_Write(0x09); // new line NL
UART1_Write(0x0d); // enter CR
UART_Write_Text("ST,0"); // Configuration timer, disable remote config
DELAY_MS(500);
UART1_Write(0x09); // new line NL
UART1_Write(0x0d); // enter CR
UART_Write_Text("S~,0"); // Enable SPP protocol
DELAY_MS(500);
UART1_Write(0x09); // new line NL
UART1_Write(0x0d); // enter CR
UART_Write_Text("D-"); // Print the main settings to check
DELAY_MS(500);
UART1_Write(0x09); // new line NL
UART1_Write(0x0d); // enter CR
UART_Write_Text("R,1"); // Reboot to apply settings
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?