https://static.assets-stash.eet-china.com/album/old-resources/2009/5/14/35b4d226-8f0c-4805-aa45-fbc5ef450e19.rar430#include<msp430x14x.h>
#define unchar unsigned char
unchar TAB[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
unchar sz[4];
unsigned long k="4000";
delay1ms()
{
unsigned char j;
for(j=0;j<120;j++);
}
void DAC(unsigned long u)
{
unsigned long us;
unsigned char i;
u="u|0xc000";
P3OUT |=BIT5; // FS="1";
_NOP();
_NOP();
_NOP();
_NOP();
P3OUT &=~BIT5; //FS=0;
for(i=0;i<16;i++)
{
us="u";
if((us&0X8000)==0X8000)
P3OUT |= BIT6;
else
P3OUT &=~ BIT6; // DIN="us"&0x8000;
P3OUT |=BIT7;
_NOP();
_NOP();
_NOP();
_NOP();
P3OUT &= ~BIT7; // CLK="0";
_NOP();
u="u"<<1;
}
P3OUT |=BIT5; // FS="1";
_NOP();
}
void disp()
{
P3OUT=0x08; //P0.0=0,选通第一位
P1OUT=TAB[sz[0]]&0x7f; //段显
delay1ms(); //延时
P1OUT=0xff; //消隐
P3OUT=0x04; //P0.1=0,选通第二位
P1OUT=TAB[sz[1]]; //段显
delay1ms(); //延时
P1OUT=0xff; //消隐
P3OUT=0x02; //P0.2=0,选通第三位
P1OUT=TAB[sz[2]]; //段显
delay1ms(); //延时
P1OUT=0xff; //消隐
P3OUT=0x01; //P0.3=0,选通第四位
P1OUT=TAB[sz[3]]; //段显
delay1ms(); //延时
P1OUT=0xff; //消隐
}
void calculate()
{
sz[0]= 2000*k/4096/ 1000;
sz[1]= 2000*k/4096%1000/100;
sz[2]= 2000*k/4096%100/10;
sz[3]= 2000*k/4096%10;
}
main()
{
P1DIR=0xff;
P3DIR=0XFF;
while(1)
{
P3OUT &=~BIT7; // CLK="0";
P3OUT |=BIT5; // FS="1";
P3OUT &=~BIT6; //DIN=0;
calculate();
disp();
DAC(k);
}
}
文章评论(0条评论)
登录后参与讨论