pic16f877
Newbie level 6
- Joined
- Feb 16, 2012
- Messages
- 12
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- tezpur university
- Activity points
- 1,388
temp_res = ADC_Read(0); // Read ADC results and send via UART
UART1_Write(IntToStr(Lo(temp_res))); // Send lower 8 bits to UART
UART1_Write(IntToStr(Hi(temp_res))); // Send upper 8 bits to UART
PORTB = temp_res;
temp_res = ADC_Read(0); // Read ADC results and send via UART
UART1_Write(IntToStr(Lo(temp_res))); // Send lower 8 bits to UART
UART1_Write(IntToStr(Hi(temp_res))); // Send upper 8 bits to UART
PORTB = temp_res;
temp_res = ADC_Read(0); // Read ADC results and send via UART
UART1_Write_Text(IntToStr(temp_res));
//After Void Main write this
ADCON0 = 0x81; //Initialize A/D Converter
ADCON1 = 0xC0;
//At last write this
PORTB = Lo(temp_res);
PORTC = Hi(temp_res); //You can connect two led's at some other port..
//After Void Main write this
ADCON0 = 0x81; //Initialize A/D Converter
ADCON1 = 0xC0;
//At last write this
PORTB = Lo(temp_res);
PORTC = Hi(temp_res); //You can connect two led's at some other port..
UART1_Write(Lo(temp_res)); // Send lower 8 bits to UART
UART1_Write(Hi(temp_res)); // Send upper 8 bits to UART
Can you tell us what value appears in the PORT B and PORTC? Are they same as what you are transmitting to UART?thanks arunsharma0731.....
UART1_Write_Text(IntToStr(temp_res));
this line works as same as my code.... my uart recieveing data but i dont know why adc reading will not shown in portB and portC ...
Code:unsigned int adc_rd; void main() { int temp_res; ADCON1 = 0x8E; // Configure AN0 pin as analog TRISA = 0xFF; // PORTA is input TRISC = 0x3F; // Pins RC7, RC6 are outputs TRISB = 0; // PORTB is output do { temp_res = ADC_Read(0); // Get 10-bit results of AD conversion PORTB = temp_res; // Send lower 8 bits to PORTB PORTC = temp_res >> 2; // Send 2 most significant bits to RC7, RC6 } while(1); }
volatile unsigned int temp_res;
PORTB = temp_res;
PORTC = (temp_res>>8)
#include "built_in.h"
unsigned int adc_rd;
void main()
{
int temp_res;
ADCON0 = 0xC1;
ADCON1 = 0x8E; // Configure AN0 pin as analog
TRISA = 0xFF; // PORTA is input
TRISC = 0x00; // Pins RC7, RC6 are outputs--> you have written 3F. actually you are suppose to write FC or 00
TRISB = 0x00; // PORTB is output
do {
temp_res = ADC_Read(0); // Get 10-bit results of AD conversion
PORTB = Lo(temp_res); // Send lower 8 bits to PORTB
PORTC = Hi(temp_res); // Send 2 most significant bits to RC7, RC6
} while(1);
}
PORTB = temp_res;
PORTC = (temp_res>>8)
ok i will try this...
is you simulate my previous code for both UART &ADC value display togather?? is it works??
individually both the code works..but when i used to make UART communication that time PORTB & PORTC LEDs are not showing results...
what the value UART recieves as well as it should show that code in my LEDs..
can you give me code?? it is a very simple code but i dont know why it shows problem..
#include "built_in.h"
unsigned int adc_rd;
void main()
{
unsigned int temp_res;
Uart1_Init(9600);
ADCON0 = 0xC1;
ADCON1 = 0x8E; // Configure AN0 pin as analog
TRISA = 0xFF; // PORTA is input
TRISC = TRISC & 0xFC; // Pins RC7, RC6 are outputs
TRISB = 0x00; // PORTB is output
Delay_ms(100);
do
{
temp_res = ADC_Read(0); // Get 10-bit results of AD conversion
//UART1_write_text("karthik");
UART1_write(Lo(temp_res)); // Send lower 8 bits to UART
Delay_ms(100);
UART1_write(Hi(temp_res)); // Send upper 8 bits to UART
PORTB = Lo(temp_res); // Send lower 8 bits to PORTB
PORTC = Hi(temp_res); // Send 2 most significant bits to RC7, RC6
}while(1);
}
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 #include "built_in.h" unsigned int adc_rd; void main() { char txt1[]="start"; char txt2[]="end"; int i=0; unsigned char rxarray[18]; //char IoutText[10]; unsigned int temp_res; unsigned char temp_res1; unsigned char temp_res2; Uart1_Init(9600); ADCON0 = 0xC1; ADCON1 = 0x8E; // Configure AN0 pin as analog TRISA = 0xFF; // PORTA is input TRISC = TRISC & 0xFC; // Pins RC7, RC6 are outputs TRISB = 0x00; // PORTB is output Delay_ms(100); do { temp_res = ADC_Read(0); //LongWordToStr(temp_res,IoutText); // convert the ADC value to string do{ for(i=0;i<5;i++) { temp_res1= txt1; rxarray[i] = temp_res1; } for(i=5;i<15;i++) { rxarray[i] = temp_res; } for(i=15;i<18;i++) { temp_res2= txt2; rxarray[i] = temp_res2; } }while(i<18); UART1_write(rxarray[i]); Delay_ms(100); }while(1); }
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?