#define _ADC
#include "..\hc908jk3.h"
#include "..\port.h"
#include "..\common.h"
// Conversion complete flag or conversion complete interrupt
// Selectable ADC clock
//#define aADSCR 0x003C // ADC Status and Control Register 142
//#define aADR 0x003D // ADC Data Register 144
//#define aADCLK 0x003E // ADC Clock Register 145
//#define aADSCR 0x003C // ADC Status and Control Register 142
#define ADC_COCO 7 // Conversion Complete 0
#define ADC_AIEN 6 // ADC Interrupt Enable 0
#define ADC_ADCO 5 // ADC Continuous Conversion 0
#define ADC_ADCH4 4 // ADC Channel select 1
#define ADC_ADCH3 3 // 1
#define ADC_ADCH2 2 // 1
#define ADC_ADCH1 1 // 1
#define ADC_ADCH0 0 // 1
//#define aADCLK 0x003E // ADC Clock Register 145
#define ADC_ADIV2 7 // ADC Clock Prescaler 0
#define ADC_ADIV1 6 // 0
#define ADC_ADIV0 5 // 0
//#define aADSCR 0x003C // ADC Status and Control Register 142
// COCO 7 // Conversion Complete 0
// 1 Conversion Complete(AIEN=0)
// 0 Conversion not Complete(AIEN=0) / CPU interrupt (AIEN=1)
// AIEN 6 // ADC Interrupt Enable 0
// 1 ADC interrupt Enabled
// 0 ADC interrupt Disabled
// ADCO 5 // ADC Continuous Conversion 0
// 1 Continuous ADC confersion
// 0 One ADC conversion
// ADCH 4:0 4 // ADC Channel select 1
// ADCH4 ADCH3 ADCH2 ADCH1 ADCH0 ADchannel Input Select
// 0 0 0 0 0 AD0 PTB0
// 0 0 0 0 1 AD1 PTB1
// 0 0 0 1 0 AD2 PTB2
// 0 0 0 1 1 AD3 PTB3
// 0 0 1 0 0 AD4 PTB4
// 0 0 1 0 1 AD5 PTB5
// 0 0 1 1 0 AD6 PTB6
// 0 0 1 1 1 AD7 PTB7
// 0 1 0 0 0 AD8 PTD3
// 0 1 0 0 1 AD9 PTD2
// 0 1 0 1 0 AD10 PTD1
// 0 1 0 1 1 AD11 PTD0
// Unused / Reserved
// 1 1 1 0 1 Vdda
// 1 1 1 1 0 Vssa
// 1 1 1 1 1 ADC power off
//#define aADCLK 0x003E // ADC Clock Register 145
// ADIV2:0 7 // ADC Clock Prescaler 0
// ADIV2 ADIV1 ADIV0 ADC Clock Rate
// 0 0 0 ADC input clock / 1
// 0 0 1 ADC input clock / 2
// 0 1 0 ADC input clock / 4
// 0 1 1 ADC input clock / 8
// 1 x x ADC input clock / 16
// 在Fvequency=1M 需要符合的条件
#define ADC_INT_ENA PIN_H(aADSCR,ADC_AIEN) // ADC Interrupt Enabled
#define ADC_INT_DIS PIN_L(aADSCR,ADC_AIEN) // ADC Interrupt Disabled
#define ADC_CONTINUE_ENA PIN_H(aADSCR,ADC_ADCO) // Continuous ADC Conversion
#define ADC_CONTINUE_DIS PIN_L(aADSCR,ADC_ADCO) // One ADC Conversion
#define ADC_PTB0 {asm lda aADSCR; asm and #0xe0; asm sta aADSCR;} // 3+2+3=8 clock
#define ADC_PTB1 {asm lda aADSCR; asm and #0xe0; asm ora #0x01; asm sta aADSCR;} // 3+2+2+3=10 clock
#define ADC_PTB2 {asm lda aADSCR; asm and #0xe0; asm ora #0x02; asm sta aADSCR;} // 3+2+2+3=10 clock
#define ADC_PTB3 {asm lda aADSCR; asm and #0xe0; asm ora #0x03; asm sta aADSCR;} // 3+2+2+3=10 clock
#define ADC_PTB4 {asm lda aADSCR; asm and #0xe0; asm ora #0x04; asm sta aADSCR;} // 3+2+2+3=10 clock
#define ADC_PTB5 {asm lda aADSCR; asm and #0xe0; asm ora #0x05; asm sta aADSCR;} // 3+2+2+3=10 clock
#define ADC_PTB6 {asm lda aADSCR; asm and #0xe0; asm ora #0x06; asm sta aADSCR;} // 3+2+2+3=10 clock
#define ADC_PTB7 {asm lda aADSCR; asm and #0xe0; asm ora #0x07; asm sta aADSCR;} // 3+2+2+3=10 clock
#define ADC_PTD3 {asm lda aADSCR; asm and #0xe0; asm ora #0x10; asm sta aADSCR;} // 3+2+2+3=10 clock
#define ADC_PTD2 {asm lda aADSCR; asm and #0xe0; asm ora #0x11; asm sta aADSCR;} // 3+2+2+3=10 clock
#define ADC_PTD1 {asm lda aADSCR; asm and #0xe0; asm ora #0x12; asm sta aADSCR;} // 3+2+2+3=10 clock
#define ADC_PTD0 {asm lda aADSCR; asm and #0xe0; asm ora #0x13; asm sta aADSCR;} // 3+2+2+3=10 clock
#define ADC_REFH {asm lda aADSCR; asm and #0xe0; asm ora #0x1d; asm sta aADSCR;} // 3+2+2+3=10 clock
// Test 结果 Vdd=Vdda=Vrefh 使 ADR 数值为 0xff
#define ADC_REFL {asm lda aADSCR; asm and #0xe0; asm ora #0x1e; asm sta aADSCR;} // 3+2+2+3=10 clock
// Test 搬苞 Vdd=Vdda=Vrefh 矫 ADR 儎篮 0x00
#define ADC_DIS {asm lda aADSCR; asm and #0xe0; asm ora #0x1f; asm sta aADSCR;} // 3+2+2+3=10 clock
// Test 搬苞 Vdd=Vdda=Vrefh 矫 ADR 儎篮 0x00
// ADC Input Clock 篮 Bus Clock
// ADC Clock 绰 1M 俊 嘎眠绢具 茄促.
#define ADC_BAUD_1M_1M {asm mov #0x00, aADCLK;}
#define ADC_BAUD_2M_1M {asm mov #0x20, aADCLK;}
#define ADC_BAUD_4M_1M {asm mov #0x40, aADCLK;}
#define ADC_BAUD_8M_1M {asm mov #0x60, aADCLK;}
#define ADC_BAUD_16M_1M {asm mov #0x80, aADCLK;}
#endif
// adc.h end
//***************************************************** |