Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Usart and VBA (Excel)

Status
Not open for further replies.

aduri

New Member
Hello,
with this sw (Mikrobasic) I'm trasmitting 3 values, obtained by pic with an ADC conversion, through serial port.
I receive the values with the sw Yperterminal in this format xxxxx,xxxxx,xxxxx;xxxxx,xxxxx,xxxxx; etc....up to 84 groups of 3.
I'd rather do this with VBA of Excel to obtain a few curves (or VB6).
Can you help me with some examples?

Thank you
Bye
Antonio


Code:
program adc3_232 

'****************************************************************************** 
' microcontroller P16F877A 
' http://www.mikroe.com/forum/viewtopic.php?t=5878&highlight=datalogger 
' Project: adconlcd 
' This project is designed to work with PIC 16F877A 
' with minor adjustments, it should work with any other PIC MCU 
' that has ADC module. 
' 
' This code demonstrates how to use library function ADC_read, and library 
' procedures and functions for LCD display (4 bit interface) 
'  It sends the ADC conversion through USART. 
'****************************************************************************** 


dim t as word 
    Text as char[20] 
    tword as string[5] 
    i as byte 

sub procedure end_adc 

    lcd_cmd(LCD_CLEAR) 
    lcd_out(1,1,"sampling") 
    lcd_chr(2,9,"E") 
    lcd_chr(2,10,"N") 
    lcd_Out(2,11,"D   ") 


    '   Usart_Write(",") 
            delay_ms(200) 
end sub 
    
sub procedure setup 

    lcd_cmd(LCD_CLEAR) 
    lcd_out(1,1,"Inizializing") 
    lcd_chr(2,9,"S") 
    lcd_chr(2,10,"T") 
    lcd_Out(2,11,"ART") 
    
    
    '   Usart_Write(",") 
            delay_ms(200) 
end sub 
sub procedure sec1 
 t  = ADC_read(0) 
    lcd_cmd(LCD_CLEAR) 
    Text  = "V1" 
    lcd_out(1,1,Text) 
        lcd_chr(2,15,"V") 
      wordtostr(t,tword) 
           Usart_Write_text(tword) 
      'lcd_chr(2,9,48+ch) 
      'lcd_chr(2,11,".") 
      lcd_out(2,3,tword) 
      Usart_Write(",") 
      delay_ms(100) 
end sub 

sub procedure sec2 
 t  = ADC_read(1) 
    lcd_cmd(LCD_CLEAR) 
    Text  = "V2" 
    lcd_out(1,1,Text) 
        lcd_chr(2,15,"V") 
      wordtostr(t,tword) 
           Usart_Write_text(tword) 
      'lcd_chr(2,9,48+ch) 
      'lcd_chr(2,11,".") 
      lcd_out(2,3,tword) 
      Usart_Write(",") 
      delay_ms(100) 
end sub 

sub procedure sec3 
 t  = ADC_read(2) 
    lcd_cmd(LCD_CLEAR) 
    Text  = "V3" 
    lcd_out(1,1,Text) 
        lcd_chr(2,15,"V") 
      wordtostr(t,tword) 
           Usart_Write_text(tword) 
      'lcd_chr(2,9,48+ch) 
      'lcd_chr(2,11,".") 
      lcd_out(2,3,tword) 
      Usart_Write(";") 
      delay_ms(100) 
end sub 

main: 
    Usart_Init(9600) 
  TRISC=0x00 
  PORTB  =2 
  TRISB  =0 
  intcon =0 
  Lcd_init(PORTD) 
  lcd_cmd(LCD_CURSOR_OFF) 
  lcd_cmd(LCD_CLEAR) 
  'Text ="curve tracer" 
  lcd_out(1,1,"datalogger") 
  Text ="A. Durighello" 
  lcd_out(2,1, Text) 
  'Setbit(PORTB,1)     'for usb project 
  OPTION_REG = $80 
  ADCON1     = $82 
  TRISA      = $FF 
  Delay_ms(200) 
  lcd_cmd(LCD_CLEAR) 
  Text  = "Samples:" 
  lcd_out(2,1,Text) 
  setup 
  for i = 0 to 83 '(84x3 samples=252) 
          sec1 
          sec2 
          sec3 
  next i 
'  while true 
'          'setup 
'          sec1 
'          sec2 
'          sec3 
''          sec4 
' 
'    wend 
'Usart_Write(";") 
end_adc 
end.
 

Pommie

Well-Known Member
Most Helpful Member
See the attached excel sheet. It is a simple demo of how to receive serial via VBA. I had to zip it as .xls files aren't allowed.

The example expects the data to contain CrLf (0x0d,0x0a) so something like a GPS receiver would work.

Mike.
 

Attachments

  • UART Example.zip
    12.2 KB · Views: 386

aduri

New Member
Thank you for your replay,
but the compressed file attached isn't on excel format.
It is without extension.
Plese send me the correct file.

Bye
Antonio
 

Number17

New Member
It worked fine for me. When I clicked the file winrar opened it for me, when I clicked the compressed file Microsoft Exel opened. It displayed a Start/stop button in the spreadsheet.
 

aduri

New Member
What extenctions did it show?
Pommie, can you send me the file without decompression?
I have a old office 97.

Bye
Antonio
 

Pommie

Well-Known Member
Most Helpful Member
I have saved it as a 97 excel file and changed the extension to .txt as .xls isn't allowed. You will need to save it and rename it. Let me know if it works.

Mike.
 

Attachments

  • UART Example97.txt
    38.5 KB · Views: 250
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top