This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Unable to check ADC signal/value on Voltage reduction project

I am working on under voltage protection relay and for this i am using the ABOV Semiconductor Microcontroller. The thing is i am stuck at one point that is not able to check the ADC Signal of my hardware i dont know if my code is wrong or am i missing the important step.

Here is my program code

#define		MAIN	1
#include	"A96G166.h"
#include	"func_def.h"
sbit led1=P2^1;      
sbit led2=P2^2;
sbit relay=P1^1;

sbit adc_R=P0^2;
sbit adc_Y=P0^3;
sbit adc_B=P1^0;
void main()
{
	cli();          	// disable INT. during peripheral setting
	port_init();    	// initialize ports
	clock_init();   	// initialize operation clock
	ADC_init();     	// initialize A/D convertor
	Timer0_init();  	// initialize Timer0
	sei();          	// enable INT.
	
	// TODO: add your main code here
	
	while(1)
	{
		led1=1;
		
	}
}

unsigned int ADC_read()
{
	// read A/D convertor
	unsigned int adcVal;
	
	while(!(ADCCRL & 0x10));	// wait ADC busy
	adcVal = ADCDRH << 8;	// read ADC high
	adcVal |= ADCDRL;	// read ADC low
	adcVal >>= 4;   	// data alignment
	return	adcVal;
}

void ADC_init()
{
	// initialize A/D convertor
	ADCCRL = 0x80;  	// setting
	ADCCRH = 0x00;  	// trigger source, alignment, frequency
}

void ADC_start(unsigned char ch)
{
	// start A/D convertor
	ADCCRL = (ADCCRL & 0xf0) | (ch & 0x0f);	// select channel
	ADCCRL |= 0x40; 	// start ADC
}

void Timer0_init()
{
	// initialize Timer0
	// 8bit timer, period = 1.000000mS
	T0CR = 0x88;    	// timer setting
	T0DR = 0x7C;    	// period count
	T0CR |= 0x01;   	// clear counter
}

void clock_init()
{
	// internal RC clock (16.000000MHz)
	unsigned char tmp;	// variable for HIRC

	tmp = OSCCR;    	// get default
	tmp &= ~(0x07 << 3);	// clear divider
	tmp |= 0x28;    	// set divider
	OSCCR = tmp;    	// Set HIRC
	SCCR = 0x00;    	// Use HIRC
}

void port_init()
{
	// initialize ports
	//   5 : P32      in  
	//  10 : P22      out LED2
	//  11 : P21      out LED1
	//  13 : AN9      in  SET VALUE
	//  14 : P11      out RELAY
	//  15 : AN7      in  B
	//  16 : AN3      in  Y
	//  17 : AN2      in  R
	//  18 : P01      in  DSCL
	//  19 : P00      in  DSDA
	P0IO = 0xF0;    	// direction
	P0PU = 0x00;    	// pullup
	P0OD = 0x00;    	// open drain
	P0DB = 0x00;    	// bit7~6(debounce clock), bit5~0=P35,P06~02 debounce
	P0   = 0x00;    	// port initial value

	P1IO = 0xFA;    	// direction
	P1PU = 0x00;    	// pullup
	P1OD = 0x00;    	// open drain
	P12DB = 0x00;   	// debounce : P23~20,P13~10
	P1   = 0x00;    	// port initial value

	P2IO = 0xFF;    	// direction
	P2PU = 0x00;    	// pullup
	P2OD = 0x00;    	// open drain
	P2   = 0x00;    	// port initial value

	P3IO = 0xFB;    	// direction
	P3PU = 0x00;    	// pullup
	P3OD = 0x00;    	// open drain
	P3   = 0x00;    	// port initial value

	// Set port functions
	P0FSRH = 0x00;  	// P0 selection High
	P0FSRL = 0x28;  	// P0 selection Low
	P1FSRH = 0x00;  	// P1 selection High
	P1FSRL = 0x22;  	// P1 selection Low
	P2FSRH = 0x00;  	// P2 selection High
	P2FSRL = 0x00;  	// P2 selection Low
	P3FSRH = 0x00;  	// P3 selection High
	P3FSRL = 0x00;  	// P3 selection Low
}