#define _DVK501_F320_EX_
#include <c8051f320.h>
#include <../../../../library/C8051F/ws_clock.h>
#include <../../../../library/C8051F/ws_delay.h>
#include <../../../../library/C8051F/ws_iic_port.h>
#include <../../../../library/C8051F/ws_pcf8591.h>
void main(void)
{
uchar *pGetDat,tmp = 0;
PCA0MD &= ~0x40; // Clear watchdog timer enable
clock_external(); // Set oscillator in external,the clock is 12M
delay_ms(100);
Check_SDA();
XBR1 = 0x40; // Enable crossbar and weak pull-ups
SMBus_Init();
Enb_Interrupt();
while(1)
{
PCF8591_getAD(MODE0,CHNL0,pGetDat);
if(*pGetDat != tmp)
{
showLine(11,1,lcd_buffer,"0x%x2",*pGetDat);
refreshLCD(lcd_buffer);
tmp = *pGetDat;
P2 = tmp;
}
delay_ms(100);
}
}
#define MODE0 0x00 //Channel0 = AIN0;
//Channel1 = AIN1;
//Channel2 = AIN2;
//Channel3 = AIN3;
#define MODE1 0x10 //Channel0 = AIN3-AIN0;
//Channel1 = AIN3-AIN1
//Channel2 = AIN3-AIN2;
#define MODE2 0x20 //Channel0 = AIN0;
//Channel1 = AIN1;
//Channel2 = AIN3-AIN2;
#define MODE3 0x30 //Channel0 = AIN1-AIN0;
//Channel1 = AIN3-AIN2;
#define CHNL0 0 //Using Channel0
#define CHNL1 1 //Using Channel1
#define CHNL2 2 //Using Channel2
#define CHNL3 3 //Using Channel3
#define DAouputEn 0x40 //0x50 or 0x60 or 0x70 is also ok!
void PCF8591_getAD(uchar mode,uchar chan,uchar *ADC)
{
SMBus_Write(0x90,mode|chan,0,1);
SMBus_Read(0x91,ADC,1);
}
void PCF8591_setDA(uchar val)
{
SMBus_Write(0x90,DAouputEn,val,2);
}