I have developed a code below for glowing LED (on port PH2) whenever switch is pressed (on PAD08). But it doesn't working.
Attached is the Schematic of the same.
Code:
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include <MC9S12XEP100.h>
#include <stdlib.h>
void delay();
void main(void)
{
PTH_PTH2= 0;
DDRH_DDRH2=1; /* PH2-LD2 as Output */
DDR0AD0_DDR0AD00=0; /* PAD08 as Input */
while(1)
{
if(PT0AD0_PT0AD00!=0b1) /* Check switch on PAD08 */
{
PTH_PTH2= 1; /* LED ON */
delay();
}
else
{
PTH_PTH2= 0; /* LED OFF */
delay();
}
}
void delay()
{
unsigned int i,j;
for(i=0;i<10000;i++);
for(j=0;j<10000;j++);
}
Hello,
You need to enable the ATD Digital input buffer of the pin.
ATD0DIEN_IEN8 = 1;
Regards,
Daniel
Its working now !
Thanks for the help