Virtual Integrated Design

DVM-001 RS232 Circuit / CCS Source Code


 


 



 






 

File:


/*
Project: DVM-001
Compiler: CCS PCM C Compiler, Version 3.178
Device: PIC12F675
Internal Oscillator Freq: 4Mhz
ADC Conversion Time: 2us
Baud Rate: 19200
Copyright 2006, Virtual Integrated Design, all rights reserved.
www.rs232pro.com
*/

#include <12F675.h>

#device adc=10
#fuses INTRC_IO,NOWDT,NOCPD,NOPROTECT,NOPUT,NOMCLR,NOBROWNOUT
#use delay(clock=4000000) //1us per instruction
#use RS232(BAUD=19200, XMIT=PIN_A4, RCV=PIN_A5)

unsigned char i,x;
unsigned char adc_samples;
unsigned char settle_time;
int16 adc_result;

void main()
{

  set_tris_a(0b101111);
  setup_adc_ports(AN2_ANALOG|VREF);
  setup_adc(ADC_CLOCK_DIV_8);
  set_adc_channel(2);

  while(1)
  {

   x=0;
   adc_result=0;
   adc_samples=16; // number of samples to average
   settle_time=50; // supply settle before adc read

   while(x!=0x01){ x=getc(); } // 1st byte
   switch(getch()) // 2cnd byte
   {
    case 0x02:
    {
      x=getc(); // 3rd byte
      adc_samples=x;
      putc(adc_samples);
      break;
    }
    case 0x03:
    {
      x=getc(); // 3rd byte
      settle_time=x;
      putc(settle_time);
      break;
    }
    case 0x04:
    {
      delay_ms(settle_time);
      adc_result = 0;
      for(i=0;i<adc_samples;i++)
      {
       adc_result += read_adc();
      }
      adc_result /= adc_samples;
      putc(adc_result>>8);
      putc(adc_result);
      break;
    }
   }
  }
}
 

Hex File:

:1000000000308A0004280000FF238316900000308F
:100010008A008E280830A000831685168312851E5C
:10002000132883160E28AB01A0172428A013242818
:100030000310851A0314AB0C201724282013A00BDF
:1000400018282B08A1002F280B30A01B0330A1007B
:10005000A10B2828A01B1628201B1E2818280034B6
:1000600083160512831205120830A100000000005B
:100070000000A1174A28A113AD0C03180516031C94
:10008000051221174A282113A10B3C28000000006B
:10009000000005160B308400840B4C28A11B3B2864
:1000A000211B432800342B308400000803196728E3
:1000B0000130A100A001A00B5B28A10B5A284A30F7
:1000C000A000A00B612800000000800B5828E92840
:1000D000A101A201A001A3012E08031D72282D0871
:1000E00003198C281030AF000310AB0DAC0DA00D20
:1000F000A30D2E082302031D7F282D082002031CB8
:1001000088282D08A002031CA3032E08A3020314B1
:10011000A10DA20DAF0B74280000052984011F302A
:10012000830583161F08F0399F0083121F130730C1
:100130009F0083160512831205162F306500831663
:100140001F08F03906389F0083121F1783161F08F7
:100150000F3910389F0083121F080C3981389F0017
:100160000830A1001F08C33921049F00A601AA017D
:10017000A9011030A7003230A800260BC028C428DF
:100180000A202108A600BD280A202108A00002306C
:1001900020020319D428033020020319DD2804307B
:1001A00020020319E62813290A202108A6002608A0
:1001B000A7002708AD00302013290A202108A60037
:1001C0002608A8002808AD00302013292808AB0015
:1001D0005328AA01A901A501270825020318FD2813
:1001E0009F149F18F12883161E088312A90703186D
:1001F000AA0A1E08AA07A50AEC282A08AC002908A2
:10020000AB00AE012708AD0068282208AA0021082B
:10021000A9002A08AB00AC012A08AD00302029084B
:0A022000AD0030201329B62863005A
:02400E0094011B
:00000001FF
;PIC12F675
 

Free RS232

 Home | Applications | Industry Links | C++ Builder Stop | Micro Stop | Hex to Ascii Chart