free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes :: Forums :: Discuss and Learn :: PIC Microcontroller Discussion
 
<< Previous thread | Next thread >>
how to dispaly the a/d value from PIC16F877 using visual basic in digital value
Go to page  1 2 [3] 4
Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
norms
Sat Mar 01 2008, 10:24PM
 User Offline
Registered Member #6079
Joined: Sat Feb 16 2008, 12:34AM

Posts: 28
Thanked 0 times in 0 posts
help needed urgently... why the code for my microcontroller wont detect a voltage? the leds don't turn on when i put 3vs as an analog input. everyone help me? and then the vb code for displaying the reading...

Back to top


Ajay
Sun Mar 02 2008, 06:35AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3753
Thanked 696 times in 655 posts
i need to see the circuit atleast..

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


sashijoseph
Sun Mar 02 2008, 12:04PM

 User Offline
Registered Member #5870
Joined: Mon Feb 04 2008, 06:26PM

Posts: 554
Thanked 124 times in 117 posts
On close examination of your code,this is the logic I figured out.....

for(;;)
{
if(usart receive buffer is full)...read usart....volts_out=value read
{ if(volts_out=511)....light up some leds and loop till receive buffer is full again
elseif(volts_out<511)....light up some leds and loop till receive buffer is full again
elseif(volts_out>511)....light up some leds and loop till receive buffer is full again
elseif(volts_out=get_adc)...read adc value,store it in EEPROM,read the stored
EEPROM value and send it to USART
}
else...PORTB=0xFF
}

Instead of the ADC you are reading in the value "Volts_out" from the USART....why?
Moreover you need to send in some value from the PC to the USART in order for the 1st ' if' statement to trigger.(if(usart receive buffer is full))
And then the variable get_adc...you are comparing volts_out to it before providing it with an initial value(you've only declared it "unsigned int get_adc;",not initialised it).

Look at the code below...this is how it should be.

unsigned int adc_val;
unsigned char volts_out;

void main()
{
USART_Init(9600);
ADCON1 = 0x80;
TRISA = 0xFF; // PORTA is input
TRISB = 0; // PORTB is output
PORTB = 0;


while (1)
{
adc_val = ADC_Read(2);
volts_out = adc_val * 5/1023;
USART_Write(volts_out);
if(adc_val==511)
{PORTB = 0xFF;}
else if(adc_val<511)
{PORTB = 0x0F;}
else
{PORTB = 0xF0;}
Delay_ms(5000);
}

}

Let there be music........
Back to top


norms
Sun Mar 02 2008, 11:46PM
 User Offline
Registered Member #6079
Joined: Sat Feb 16 2008, 12:34AM

Posts: 28
Thanked 0 times in 0 posts
at this moment my current code for my microcontroller 16F877, please correct it and write the code if you don't mind... please... really reallly need it.

void main()
{
int limit = 512;
int vout;
int adc;
int x;
int value;
int temp1;
int temp2;
int exit = 1;

Usart_Init(2400);
ADCON0 = 0x80;
ADCON1 = 0x80;
ADCON0.ADON = 1; // Enables A/D Conversion
TRISB = 0;
PORTB = 0;
RCSTA = 0x90;
TXSTA = 0x24;
Delay_ms(100);

for(;;)
{
if(Usart_Data_Ready())
{
exit=1;
PORTB=0;
vout=Usart_Read();
Delay_ms(100);

if(vout == 512) // Within the 240 Voltage Range, equal to 2.5 volts
{
do
{
PORTB.F1 = 1;
PORTB.F2 = 1;
PORTB.F3 = 1;
PORTB.F4 = 1;
PORTB.F5 = 1;
PORTB.F6 = 1;
PORTB.F7 = 1;
Delay_ms(1000);
if(Usart_Data_Ready())
{
exit=0;
}
}
while(exit);
}
else if(vout > 512) // Greater than 240 Volts, greater than 2.5 volts
{
do
{
PORTB.F1 = 1;
PORTB.F3 = 1;
PORTB.F5 = 1;
PORTB.F7 = 1;
Delay_ms(1000);
if(Usart_Data_Ready())
{
exit=0;
}
}
while(exit);
}
else if (vout < 512) // Less than 240 volts, less than 2.5 volts
{
do
{
PORTB.F2 = 0;
PORTB.F4 = 0;
PORTB.F6 = 0;
Delay_ms(1000);
if (Usart_Data_Ready())
{
exit = 0;
}
}
while(exit);
}
else if (vout == 0)
{
do
{
PORTB.F1=0;
PORTB.F2=0;
PORTB.F3=0;
PORTB.F4=0;
PORTB.F5=0;
PORTB.F6=0;
PORTB.F7=0;
if(Usart_Data_Ready())
{
exit=0;
}
}
while(exit);
}
else if(vout == adc)
{
do
{
ADRESH=0;
ADRESL=0;
ADCON0.GO=1;
Delay_ms(100);
value=Adc_Read(0);
Delay_ms(100);
exit=0;
temp1=ADRESH;
temp2=ADRESL;
Delay_ms(1000);
Eeprom_Write(0,temp1);
Delay_ms(20);
Eeprom_Write(1,temp2);
Delay_ms(70);
Usart_Write(Eeprom_Read(0));
Delay_ms(20);
Usart_Write(Eeprom_Read(1));
Delay_ms(50);
if(Usart_Data_Ready())
{
exit=0;
}
}
while(exit);
}
}
else
{
PORTB=0xff;
}
}
}
Back to top


norms
Sun Mar 02 2008, 11:48PM
 User Offline
Registered Member #6079
Joined: Sat Feb 16 2008, 12:34AM

Posts: 28
Thanked 0 times in 0 posts
my vb code... please check and correct it... thank you very much guys...

Private Sub CmdExit_Click()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End
End Sub
Private Sub Form_Load()
MSComm1.InputLen = 0
MSComm1.CommPort = 1
MSComm1.Settings = "2400,N,8,1"
End Sub
Private Sub Timer1_Timer()
Dim BytesToRead As Integer
Dim adc As Variant
MSComm1.PortOpen = True
BytesToRead = 1
Do
DoEvents
Loop Until MSComm1.InBufferCount = BytesToRead
adc = MSComm1.Input
Text1.Text = (((Asc(adc) * 0.01) * 230) / 2.5) & " Volts AC"
MSComm1.PortOpen = False
End Sub
Back to top


norms
Mon Mar 03 2008, 12:09AM
 User Offline
Registered Member #6079
Joined: Sat Feb 16 2008, 12:34AM

Posts: 28
Thanked 0 times in 0 posts
this is my circuit

Back to top


norms
Mon Mar 03 2008, 12:32AM
 User Offline
Registered Member #6079
Joined: Sat Feb 16 2008, 12:34AM

Posts: 28
Thanked 0 times in 0 posts
the Tx and Rx were put incorrectly... Rx should in the Tx place...
Back to top


sashijoseph
Mon Mar 03 2008, 11:17AM

 User Offline
Registered Member #5870
Joined: Mon Feb 04 2008, 06:26PM

Posts: 554
Thanked 124 times in 117 posts
Like I pointed out ealier your PIC code won't work.For eg.
CODE:
if(Usart_Data_Ready())

why are you checking the (PIC's) serial port input buffer?Are you sending sth into the PIC's serial port?If not then why use this check?

Then you have
CODE:
vout=Usart_Read();

You should be getting the value from the ADC rather than the serial port.

Similarly there are plenty of flaws.......

Look at the code below.This is all you need to read in ADC value and send it as two bytes to the PC's serial port.

unsigned int adc_val;
unsigned char low_byte,hi_byte;
void main()
{
USART_Init(9600);
ADCON1 = 0;
TRISA = 0xFF; // PORTA is input
TRISB = 0; // PORTB is output
PORTB = 0;

while (1)
{
adc_val = ADC_Read(2); //get ADC value
low_byte = adc_val; //split the 2-byte integer into 2 separate bytes
hi_byte = adc_val >> 8; //for sending to pc serial port
USART_Write(low_byte); //send the 1st (lower) byte
USART_Write(hi_byte); //send the upper byte
if(adc_val==511) //if ADC value read in is 511
{PORTB = 0xFF;} //display some LED's on PORTB
else if(adc_val<511)
{PORTB = 0x0F;}
else
{PORTB = 0xF0;}
Delay_ms(5000); //gather a sample after 5 secs.
}
}

[ Edited Mon Mar 03 2008, 11:18AM ]

Let there be music........
Back to top


norms
Mon Mar 03 2008, 11:11PM
 User Offline
Registered Member #6079
Joined: Sat Feb 16 2008, 12:34AM

Posts: 28
Thanked 0 times in 0 posts
thanks sashijoseph for the help. appreciate it very much... ill test it tonight ill keep in touchwith you. you save my life...
Back to top


norms
Mon Mar 03 2008, 11:35PM
 User Offline
Registered Member #6079
Joined: Sat Feb 16 2008, 12:34AM

Posts: 28
Thanked 0 times in 0 posts
sashijoseph wrote ...

Like I pointed out ealier your PIC code won't work.For eg.
CODE:
if(Usart_Data_Ready())

why are you checking the (PIC's) serial port input buffer?Are you sending sth into the PIC's serial port?If not then why use this check?

Then you have
CODE:
vout=Usart_Read();

You should be getting the value from the ADC rather than the serial port.

Similarly there are plenty of flaws.......

Look at the code below.This is all you need to read in ADC value and send it as two bytes to the PC's serial port.

unsigned int adc_val;
unsigned char low_byte,hi_byte;
void main()
{
USART_Init(9600);
ADCON1 = 0;
TRISA = 0xFF; // PORTA is input
TRISB = 0; // PORTB is output
PORTB = 0;

while (1)
{
adc_val = ADC_Read(2); //get ADC value
low_byte = adc_val; //split the 2-byte integer into 2 separate bytes
hi_byte = adc_val >> 8; //for sending to pc serial port
USART_Write(low_byte); //send the 1st (lower) byte
USART_Write(hi_byte); //send the upper byte
if(adc_val==511) //if ADC value read in is 511
{PORTB = 0xFF;} //display some LED's on PORTB
else if(adc_val<511)
{PORTB = 0x0F;}
else
{PORTB = 0xF0;}
Delay_ms(5000); //gather a sample after 5 secs.
}
}


what happened to the USART_Write(volts_out)? in your first correction you have it, then now its gone, replace by the low and high byte... please enlightened me with this...

then in my vb pro, do i need to change the BytesToRead = 1 to 2? and then the "adc=MSComm1.Input"
what will be my input here? thanks
Back to top


Go to page  1 2 [3] 4  

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems