static int do_i2c_pcf8591(int argc, const char* const* argv)
{
	if(argc == 1 || strcmp(argv[1], "read") == 0){

		if((IS_ALREADY_INITED || PCF8591_Init()) && PCF8591_Read()){
			if(argc != 1){
				console_printf( "A0-A3: " );
			}
			console_printf( "%d %d %d %d\n", LAST_PCF8591_A[0], LAST_PCF8591_A[1], LAST_PCF8591_A[2], LAST_PCF8591_A[3]);
		}else{
			console_printf( "Failed to read value\n" );
		}
	} else

	if(strcmp(argv[1], "write") == 0){

		if( argc < 3 ){
			console_printf( "Value not specified\n" );
			return 0;
		}

		console_printf(PCF8591_Write(atoi(argv[2]))?"Ok":"Failed to write value");

	} else

	if(strcmp(argv[1], "init") == 0){

		console_printf( PCF8591_Init() ? "Ok\n":"Failed\n" );
	} 

	return 0;
}
bool PCF8591_Init()
{
	//TODO: configure for differential input
	if(PCF8591_Read()){
		IS_ALREADY_INITED = true;
		return true;
	}
	return false;
}
Example #3
0
void main()
{
	uint8 dat;
	uint16 temp;
	uint8 LcdBuff[6];
	LCD1602_Init();
	while(1)
	{
		dat=PCF8591_Read(0);
		temp=dat*125/64;
		LcdBuff[0]=temp/100+'0';
	    LcdBuff[1]='.';
		LcdBuff[2]=temp/10%10+'0';
		LcdBuff[3]=temp%10+'0';
		LcdBuff[4]='V';
		LcdBuff[5]='\0';
		LCD1602_Show(0,0,LcdBuff,5);		
	}
}