...and this is the original code from this schematic :
Code:
'****************************************************************
'* Name : VOLTMETRE.BAS *
'* Author : [Erol Tahir Erdal] *
'* Notice : Copyright (c) 2005 [ETE] *
'* : All Rights Reserved *
'* Date : 01.03.2005 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
DEFINE LCD_DREG PORTB 'LCD data bacaklarý hangi porta baðlý?
DEFINE LCD_DBIT 4 'LCD data bacaklarý hangi bitten baþlýyor?
DEFINE LCD_RSREG PORTB 'LCD RS Bacaðý Hangi Porta baðlý ?
DEFINE LCD_RSBIT 1 'LCD RS bacaðý Hangi Bite baðlý ?
DEFINE LCD_EREG PORTB 'LCD Enable Bacaðý Hangi Porta baðlý?
DEFINE LCD_EBIT 3 'LCD Enable Bacaðý Hangi bite baðlý ?
define lcd_RWREG PORTB
define LC_RWBIT 2
DEFINE LCD_BITS 4 'LCD 4 bit mi yoksa 8 bit olarak baðlý?
DEFINE LCD_LINES 2 'LCD Kaç sýra yazabiliyor
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
@ DEVICE pic16F877
@ DEVICE pic16F877, WDT_off
@ DEVICE pic16F877, PWRT_ON
@ DEVICE pic16F877, PROTECT_OFF
@ DEVICE pic16F877, XT_OSC
ADCON1=%10001110
TRISA=%00010011
TRISB=0
TRISC=0
VOLT VAR WORD
HAM VAR WORD
HVD var word
AMPER var word
MV VAR BYTE
MA VAR BYTE
PORTB=0
PORTA=0
VOLT=0
PAUSE 100
LCDOUT $FE,1
BASLA:
ADCIN 0,HAM
BAK: IF ADCON0.2=1 THEN BAK
PAUSE 5
GOSUB HESAPV
ADCIN 1,HAM
PAUSE 5
GOSUB HESAPA
GOSUB EKRAN
PAUSE 1500
GOTO BASLA
EKRAN:
' LCDOUT$FE,2,"HAM=",#HAM 'gerekirse okanan ham deðerini görmek için
LCDOUT $FE,$02,"VOLT =",DEC VOLT,",",DEC1 MV 'dec2 yazdýk çünki virgülden sonra 2 hane hassasiyetimiz var.
LCDOUT $FE,$C0,"AMPER=",DEC2 AMPER,",",DEC2 MA
' LCDOUT $FE,$C0,"AMPER=",DEC HVD
RETURN
HESAPV: '0-25V deðerlerini oukuyup göstermek içindir
HVD=((HAM+1)*/875)/10 'bu ifade aslýnda (HAM+1)*625/256 nýn karþýlýðýdýr
'CARPAN=625 yani ((25x10)/1024)*256 sonuç 62,5 çýktýðý için 625 almak için
' 10 yerine 100 ile çarpýyoruz. yani CARPAN=((25*100)/1024)*256
VOLT=HVD/10 'baþlangýçta 100 ile çarpýlmýþ halini hesaplamýþ idik ohalde 100 e böleceðiz
MV=(HVD)//10 'seaplanan sayýný 100 bölünmesinden kalan sayý ondalýk hanesidir
RETURN
' Formül;
' Okunacak Maksimum Volt=OMV olsun
' CARPAN= ((OMV*10)/1024) * 256 veya ((OMV*100)/1024)*256
' CARPAN deðerini 3 haneli rakam olarak kullanmaya gayret edin.
' þayet 62,5 gibi 2 haneli bir rakam çýkar ise bunu 625 kabul edin ve
' (OMV * 10) deðerini (OMV * 100) olarak kullanýn. Sonuçta hesaplanan volt deðerini
' 10 yerine 100'e bölmeniz gerekecek tabiiki. OV hesabýnda da Yine 100 bölünmüþ
' deðerden kalaný hesaplamak gerekecek. Yukarýdaki örnekte olduðu gibi.
' Hesaplanacak Volt Deðeri =HVD olsun
' ADC den okunan Deðer HAM olsun
' HVD=(HAM+1)*/CARPAN bulunacak deðer gerçek volt deðerinin 10 ile çarpýlmýþ halidir.
' Tamsayý VOLT (TV)= HVD/10 veya TV=HVD/100
' Ondalýk VOLT (OV)= HVD//10 veya OV=HVD//100
'Ekrana yazdýrýrken;
' LCDOUT $FE,2,"VOLT:", DEC TV,",",DEC1 OV veya DEC2 OV olacaktýr
HESAPA:
HVD=(HAM+1)*/250
AMPER=HVD/100
MA=HVD//100
RETURN
Credits to 320volts.com !
Bookmarks