#include #include #include #define IOBASE 0x300 #define AD_CHNL IOBASE #define AD_HIGH IOBASE+1 #define AD_LOW IOBASE+2 #define dac_chnnl(i) outportb(AD_CHNL,(unsigned char)i); void dac_value(int i) { unsigned char low,high; high = (i >> 4) & 0xff; low = (i << 4) & 0xf0; outportb(AD_HIGH,high); outportb(AD_LOW,low); } void main(void) { int c; printf("\n Input the channel:"); scanf("%d",&c); dac_chnnl(c); /* select the DAC channel */ printf(" Press any key to continue .."); /* wait key */ getch(); c = 0; do { dac_value(c++); c = c & 0xfff; } while(kbhit()==0); }