求一个用c#做的单片机程序下载软件 有人做过吗
答案:2 悬赏:60
解决时间 2021-03-02 16:15
- 提问者网友:我稀罕你
- 2021-03-02 05:32
求一个用c#做的单片机程序下载软件 有人做过吗
最佳答案
- 二级知识专家网友:爱情是怎么炼成的
- 2021-03-02 06:07
//实验: 四位数码管8通道循环显示AD转换电压
//单片机:ATMEGA16L
//作者: jia
//日期: 2008
//在硬件上已调试通过
#include
#define uchar unsigned char
#define uint unsigned int
//#define vref 2048 //转换值
uchar num[4];
//共阳数码管位码0~9
//uchar Table[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
//uchar Data[4]={0xC0,0xC0,0xC0,0xC0};
//AD转换程序
uint ADC_Convert(void)
{uint temp1,temp2;
temp1=(uint)ADCL;
temp2=(uint)ADCH;
temp2=(temp2<<8)+temp1;
return(temp2);
}
//数据处理和显示
void Process(uint i,uchar *p)
{
uint temp;
//i=i/204.8;
//temp=(unsigned int)(((unsigned long)((unsigned long)i*vref))/1024);
temp=i;
p[0]=temp/1000;
temp=temp%1000;
p[1]=temp/100;
temp=temp%100;
p[2]=temp/10;
temp=temp%10;
p[3]=temp;
}
//i/o口初始化
void port_init(void)
{
DDRA=0x00; //设置A口为不带上拉输入;
PORTA=0x00;
PORTB=0xff;
DDRB=0xff;
DDRC=0xFF;
PORTC=0x00;
DDRD=0xff; //设置C口为推挽1输出;
PORTD=0xff;
ADMUX=0x00; //选择第1通道ADC0;AVCC, AREF 引脚外加滤波电容电压
ADCSR=0xe6; //125K转换速率,自由转换模式;启动AD转换器;
}
void init_devices(void)
{ port_init();
//stop errant interrupts until set up
// CLI(); //disable all interrupts
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
//SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void Delay(int del)
{
//unsigned char i,j;
for(del;del>=0;del--);
// {
// for(j=10;j>0;j--);
// ;
//}
}
void disp(void)
{
uchar LEDValue[11]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xff}; //0-9
uchar i,k,senddat;
//num[5]=10;
num[4]=10;
for(k=0;k<=5;k++)//发送6个字节
{
senddat=LEDValue[num[5-k]];
for(i=0;i<=7;i++)//发送8位
{
if(senddat&0x01!=0x00)//取最低位数据送给IO口
PORTB |= 0x01;
else
PORTB &= 0xfe;
PORTB &= 0xfd;//PA2为零
Delay(3);
PORTB |= 0x02; //PA2为1
Delay(3);
senddat>>=1;
}
}
}
//主程序
void main(void)
{uint i;
init_devices();
Delay(30);
//for(i=0;i<5;i++) //延时3s待系统稳定?
num[5]=0;
disp();
//Delay(30000);
//Delay(30000);
//Delay(30000);
//Delay(30000);
while(1)
{
while(!(ADCSRA & (1 << ADIF)));
i=ADC_Convert();
ADCSRA &= ~(1 << ADIF);
ADCSRA &= ~(1 << ADEN);
Process(i,num);
num[5]=ADMUX;
disp();
Delay(30000);
Delay(30000);
Delay(30000);
Delay(30000);
Delay(30000);
Delay(30000);
Delay(30000);
Delay(30000);
Delay(30000);
ADMUX++; //选择0~7道ADC0;AVCC, AREF 引脚外加滤波电容电压
ADMUX%=8;
ADCSR=0xe6;
}
}
//单片机:ATMEGA16L
//作者: jia
//日期: 2008
//在硬件上已调试通过
#include
#define uchar unsigned char
#define uint unsigned int
//#define vref 2048 //转换值
uchar num[4];
//共阳数码管位码0~9
//uchar Table[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
//uchar Data[4]={0xC0,0xC0,0xC0,0xC0};
//AD转换程序
uint ADC_Convert(void)
{uint temp1,temp2;
temp1=(uint)ADCL;
temp2=(uint)ADCH;
temp2=(temp2<<8)+temp1;
return(temp2);
}
//数据处理和显示
void Process(uint i,uchar *p)
{
uint temp;
//i=i/204.8;
//temp=(unsigned int)(((unsigned long)((unsigned long)i*vref))/1024);
temp=i;
p[0]=temp/1000;
temp=temp%1000;
p[1]=temp/100;
temp=temp%100;
p[2]=temp/10;
temp=temp%10;
p[3]=temp;
}
//i/o口初始化
void port_init(void)
{
DDRA=0x00; //设置A口为不带上拉输入;
PORTA=0x00;
PORTB=0xff;
DDRB=0xff;
DDRC=0xFF;
PORTC=0x00;
DDRD=0xff; //设置C口为推挽1输出;
PORTD=0xff;
ADMUX=0x00; //选择第1通道ADC0;AVCC, AREF 引脚外加滤波电容电压
ADCSR=0xe6; //125K转换速率,自由转换模式;启动AD转换器;
}
void init_devices(void)
{ port_init();
//stop errant interrupts until set up
// CLI(); //disable all interrupts
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
//SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void Delay(int del)
{
//unsigned char i,j;
for(del;del>=0;del--);
// {
// for(j=10;j>0;j--);
// ;
//}
}
void disp(void)
{
uchar LEDValue[11]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xff}; //0-9
uchar i,k,senddat;
//num[5]=10;
num[4]=10;
for(k=0;k<=5;k++)//发送6个字节
{
senddat=LEDValue[num[5-k]];
for(i=0;i<=7;i++)//发送8位
{
if(senddat&0x01!=0x00)//取最低位数据送给IO口
PORTB |= 0x01;
else
PORTB &= 0xfe;
PORTB &= 0xfd;//PA2为零
Delay(3);
PORTB |= 0x02; //PA2为1
Delay(3);
senddat>>=1;
}
}
}
//主程序
void main(void)
{uint i;
init_devices();
Delay(30);
//for(i=0;i<5;i++) //延时3s待系统稳定?
num[5]=0;
disp();
//Delay(30000);
//Delay(30000);
//Delay(30000);
//Delay(30000);
while(1)
{
while(!(ADCSRA & (1 << ADIF)));
i=ADC_Convert();
ADCSRA &= ~(1 << ADIF);
ADCSRA &= ~(1 << ADEN);
Process(i,num);
num[5]=ADMUX;
disp();
Delay(30000);
Delay(30000);
Delay(30000);
Delay(30000);
Delay(30000);
Delay(30000);
Delay(30000);
Delay(30000);
Delay(30000);
ADMUX++; //选择0~7道ADC0;AVCC, AREF 引脚外加滤波电容电压
ADMUX%=8;
ADCSR=0xe6;
}
}
全部回答
- 1楼网友:两不相欠
- 2021-03-02 07:32
不可以 不是说c#不行 而是单片机不支持
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯