ユーザ用ツール

サイト用ツール


softdev:tempmeter3

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
softdev:tempmeter3 [2013/01/07 23:46] – [ソース] kingsoftdev:tempmeter3 [2013/07/15 20:25] (現在) – 外部編集 127.0.0.1
行 18: 行 18:
  
 ポート初期化他 ポート初期化他
-<code c>+<code c++>
 #include <pic.h> #include <pic.h>
- 
 #define _XTAL_FREQ 4000000 #define _XTAL_FREQ 4000000
- 
 #define SPDAT GP0 #define SPDAT GP0
 #define SPCLK GP1 #define SPCLK GP1
行 50: 行 48:
 __CONFIG(CP_OFF & BOREN_ON  & PWRTE_ON & WDTE_OFF & FOSC_INTOSCIO) ; __CONFIG(CP_OFF & BOREN_ON  & PWRTE_ON & WDTE_OFF & FOSC_INTOSCIO) ;
  
 +main()
 +{
 +/* Note: The ANSEL and CMCON0 registers must be initialized to configure an analog
 + * channel as a digital input. Pins configured as analog inputs will read ‘0’.
 + */
 + GPIO   = 0x00; /* IO initialize */
 + CMCON0 = 0x07; /* Comparator function CM210=111(disable)*/
 + ANSEL  = 0x54; // ADCS=101;4us  GP2だけAN2として使う。
 + OSCCON = 0x60; /* 4MHz */
 + TRISIO = 0x1C; /* IO direction 543210=011100 0=Out,1=In */
 + ADCON0 = 0x89; // 10001001
 + IOC    = 0x10; // IOC4 is enable
 + INTCON = 0x88; // GIE , GPIE
 +
 + ADFM=1; 
 + ADON = 1;
 +
 +</code>
 +
 +ADC計算部(ごめん、long使ってる)
 +<code c>
 +char avg,fugo,d3,d2,d1,loop;
 +int andata,temp;
 +long temp10; // AD変換値の10倍で途中まで計算(long型とする)
 +
 +andata = 0;
 +for(avg=0;avg<HEIKIN;avg++){
 +  __delay_ms(5);
 +  GO = 1;
 +  while(GO);
 +  andata += (ADRESH<<8) | ADRESL ;
 +}
 +andata = andata / HEIKIN ;
 +temp10 = (long)andata * 5000 - 2457600;
 +temp10 =  temp10 / 4096;
 +temp   = (int)temp10;
 </code> </code>
  
  
  
softdev/tempmeter3.1357569967.txt.gz · 最終更新: 2013/07/15 20:28 (外部編集)