Discussion in "PIC Microcontroller Discussion" started by    norms    Feb 16, 2008.
Tue Mar 04 2008, 01:30 pm
#31
The previous USART_Write(volts_out) would send out the value volts_out which had been declared as char hence only rounded off values(ie1,2,3,4,5) would be sent instead of say 1.87 or 2.54 etc.It was only for checking proper working.
The actual value received by the adc,which is an integer (2bytes) is split into two bytes and sent to the PC as Low_byte and Hi_byte.In the PC you can then 'join' the 2 bytes to the original int and then convert it to the appropriate voltage reading to be displayed. Hope it's clear.
I would suggest doing things step by step.First program the PIC and see if the LED's are working correctly.Then use Hyperterminal and check if the serial code is OK.Finally make the VB program.
Tue Mar 04 2008, 03:07 pm
#32
thanks.. ill try it tonight...
Tue Mar 04 2008, 08:54 pm
#33
hmm im trying it right now, and it can't light the leds on... does something in my circuit is wrong? the schematic diagram of my pic was posted before here. kindly check it sashjoseph, ive changed the ADCON1 to ADCON0, so the input will be put in AN0 in pin number 2, am i right?
Tue Mar 04 2008, 10:48 pm
#34
heres my code and its working, i can light the leds now..... hope you can add the necessary codes for transmitting the signal to the serial port... pls help...


void main()
{
int limit=512;
int value;
TRISA=0xff; // Configure PORTA as analog input
TRISB=0; // Configure PORTB as output
PORTA=0;
PORTB=0;
ADCON0=0b10000000;
ADCON1=0b10001110;
ADCON0.ADON=1; // Enable ADC
for(;;)
{
ADCON0.GO=1;
Delay_us(10);
value=Adc_Read(0);
if(value>=512) // value is greater or equal to 2.5V
{
PORTB.F0=1;
PORTB.F2=1;
PORTB.F4=1;
PORTB.F6=1;
Delay_ms(100);
PORTB.F0=0;
PORTB.F2=0;
PORTB.F4=0;
PORTB.F6=0;
Delay_ms(100);
}
else if(value<512)
{
PORTB.F1=1;
PORTB.F3=1;
PORTB.F5=1;
PORTB.F7=1;
Delay_ms(100);
PORTB.F1=0;
PORTB.F3=0;
PORTB.F5=0;
PORTB.F7=0;
Delay_ms(100);
}
Delay_ms(3000);
}
}



and pls help me in my vb program... here is my first vb program...

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 = "9600,N,8,1"
End Sub
Private Sub Timer1_Timer()
Dim BytesToRead As Integer
Dim value As Variant
MSComm1.PortOpen = True
BytesToRead = 1
Do
DoEvents
Loop Until MSComm1.InBufferCount = BytesToRead
value = MSComm1.Input
Text1.Text = (((Asc(value) * 0.01) * 230) / 2.5) & " Volts AC"
MSComm1.PortOpen = False
End Sub

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

carpinteyrowrl
Fri Apr 19 2024, 02:51 pm
DonaldJAX
Fri Apr 19 2024, 01:08 pm
Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am
utaletxcyw
Wed Apr 17 2024, 10:21 am