STMicroelectronics STM8 Manual page 59

Table of Contents

Advertisement

void ADC1_setup(void)
{
ADC1_DeInit();
ADC1_Init(ADC1_CONVERSIONMODE_SINGLE,
ADC1_AWDChannelConfig(ADC1_CHANNEL_1, ENABLE);
ADC1_SetHighThreshold(600);
ADC1_SetLowThreshold(200);
ADC1_Cmd(ENABLE);
}
void lcd_print(unsigned char x_pos, unsigned char y_pos, unsigned int value)
{
char chr = 0x00;
chr = ((value / 1000) + 0x30);
LCD_goto(x_pos, y_pos);
LCD_putchar(chr);
chr = (((value / 100) % 10) + 0x30);
LCD_goto((x_pos + 1), y_pos);
LCD_putchar(chr);
chr = (((value / 10) % 10) + 0x30);
LCD_goto((x_pos + 2), y_pos);
LCD_putchar(chr);
chr = ((value % 10) + 0x30);
LCD_goto((x_pos + 3), y_pos);
LCD_putchar(chr);
}
Explanation
The code for the AWD example is just as the one demonstrated in the ADC example. However, this
time the ADC channel is channel 1 (PB1). Setting up the AWD is simple. We just need to set the limits,
specify which channel to be monitored and enable the AWD unit.
ADC1_AWDChannelConfig(ADC1_CHANNEL_1, ENABLE);
ADC1_SetHighThreshold(600);
ADC1_SetLowThreshold(200);
Here we have set 600 and 200 ADC counts as upper and lower limits respectively.
ADC1_CHANNEL_1,
ADC1_PRESSEL_FCPU_D10,
ADC1_EXTTRIG_GPIO,
DISABLE,
ADC1_ALIGN_RIGHT,
ADC1_SCHMITTTRIG_CHANNEL1,
DISABLE);

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the STM8 and is the answer not in the manual?

Questions and answers

Table of Contents

Save PDF