敦晨科技
所在地区:
全国
首页
服务/硬件产品
行业解决方案
案例
方案概述:
本次数控稳压电源设计基于51单片机,通过控制输出来实现对电源的电压控制和显示功能。主要的设计流程包括主要输出部分、预置数部分和显示部分。代码实现部分包括定时器的初始化、延时函数、数码管显示函数等。通过该设计方案,可以实现对电源电压的精确控制和显示。
解决方案:数控稳压电源设计报告
本次数控稳压电源设计基于51单片机,通过控制输出来实现对电源的电压控制和显示功能。主要的设计流程如下:
1. 主要输出部分:通过设置4X4矩阵键盘,可以任意置数、加减和自动步进,实现输出波形的控制。
2. 预置数部分:通过拨码开关来预置电压值。
3. 显示部分:通过51单片机对两位数码管进行动态扫描,实现电压值的显示。
以下是代码实现部分:
```c
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar aa, bb, cc, dd, jj, ii, jjj, iii, key, j;
uchar time1 = 0;
sbit led1 = P2^0;
sbit led2 = P2^1;
sbit ce = P2^4;
#define timer0_count 0xfc18 //定时器初值,设置time0 1/1000秒中断一次
const seg[10] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90}; //数码管的显示
const seg_point[10] = {0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x10}; //有小数点的数码管显示
uchar scan1; //用来分别显示2个数码管
uchar scan2;
uchar counter[2] = {0xf1, 0xf2};
uchar vout = 0; //j_片选,vout_电压输出
static void timer0_initialize(void) //timer0的初始化
{
EA = 0; //中断控制器IE--停止接受中断
TR0 = 0; //停止计时
TMOD = 0x01; //设置工作方式为1
TL0 = (timer0_count & 0x00ff);
TH0 = (timer0_count >> 8); //设置time0 初值
PT0 = 1; //设置timer0高优先级
ET0 = 1; //允许timer0中断
TR0 = 1; //开始计时
EA = 1; //开所有中断
}
void delay(uint t) //tms的延时
{
uchar i;
uint j;
for (j = 0; j < t; j++)
for (i = 0; i < 40; i++)
;
}
void shuc(void)
{
uchar nn;
vout = 2 * (scan2 * 10 + scan1); //输出的数字量
P1 = vout;
for (nn = 0; nn < 250; nn++)
;
nn = 0; //输出是存在D/A转换时间差所以要延时
}
void shaom(void)
{
P3 = 0x0f; //扫描是否有按键按下
if ((P3 & 0x0f) != 0x0f)
dd = 0;
else
dd = 1;
}
void zdbj(void) //自动步进
{
uchar rr;
jj = scan2;
ii = scan1;
shaom();
for (; jj < 10; jj++)
{
for (; ii < 10; ii++)
{
if (dd)
{
scan1 = ii;
scan2 = jj;
shuc();
for (rr = 0; rr < 250; rr++)
{
shaom();
if (dd)
delay(70);
else
break;
}
if (jj == 9 && ii == 9)
{
ii = 0;
jj = 0;
}
}
else
{
jj = 10;
ii = 10;
}
}
ii = 0;
}
jj = 0;
shaom();
for (; dd == 0;)
shaom();
}
void sjb(void) //三角波
{
uchar max;
max = vout;
shaom();
for (; dd;)
{
for (iii = 0; iii < max; iii = iii + 2)
{
P1 = iii;
shaom();
delay(7);
if (dd == 0)
break;
}
if (dd == 0)
break;
for (; iii > 0; iii = iii - 2)
{
P1 = iii;
shaom();
delay(10);
if (dd == 0)
break;
}
if (dd == 0)
break;
}
P1 = max;
shaom();
for (; dd == 0;)
shaom();
}
unsigned char keyscan(void) //键盘扫描函数,使用行列反转扫描法
{
unsigned char cord_h, cord_l; //行列值中间变量
P3 = 0x0f; //行线输出全为0
cord_h = P3 & 0x0f; //读入列线值
if (cord_h != 0x0f) //先检测有无按键按下
{
delay(70); //去抖
if ((P3 & 0x0f) != 0x0f)
{
cord_h = P3 & 0x0f; //读入列线值
P3 = cord_h | 0xf0; //输出当前列线值
cord_l = P3 & 0xf0; //读入行线值
while ((P3 & 0xf0) != 0xf0) //等待松开并输出
{
time1 = time1 + 1;
return (cord_h + cord_l); //键盘最后组合码值
}
}
}
return (0); //返回该值
}
void timer0_isr(void) interrupt 1 //timer0中断
//用于LED数码管的动态显示
{
TR0 = 0; //停止时钟0
P2 = counter[j];
switch (j)
{
case 0:
P0 = seg[scan1];
break;
case 1:
P0 = seg_point[scan2];
break;
default:
break; //j为其他情况是跳出循环
}
j++;
if (j == 2)
j = 0;
TL0 = (timer0_count & 0x00ff);
TH0 = (timer0_count >> 8); //设置time0 初值
TR0 = 1; //开时钟
}
void main(void)
{
ce = 0;
delay(5);
scan1 = (P3 / 2) % 10;
scan2 = P3 / 20;
ce = 1;
delay(5);
shuc();
timer0_initialize(); //定时器初始化用于LED显示
do
{
key = keyscan();
if (time1 == 1)
switch (key)
{
case 0xee:
aa = 1;
break;
case 0xed:
aa = 2;
break;
case 0xeb:
aa = 3;
break;
case 0xe7:
aa = 4;
break;
case 0xde:
aa = 5;
break;
case 0xdd:
aa = 6;
break;
case 0xdb:
aa = 7;
break;
case 0xd7:
aa = 8;
break;
case 0xbe:
aa = 9;
break;
case 0xbd:
aa = 0;
break;
case 0xbb:
time1--;
break;
case 0xb7: //三角波
{
time1 = 0;
sjb();
}
break;
case 0x7e: //加
{
time1 = 0;
scan1++;
if (scan1 == 10)
{
scan1 = 0;
scan2++;
if (scan2 == 10)
scan2 = 0;
}
shuc();
}
break; //c
case 0x7d: //减
{
time1 = 0;
scan1--;
if (scan1 == -1)
{
scan1 = 9;
scan2--;
if (scan2 == -1)
scan2 = 9;
}
shuc();
}
break;
case 0x7b: //自动步进
{
time1 = 0;
zdbj();
}
break; //e
case 0x77:
time1--;
break;
}
if (time1 == 2)
switch (key)
{
case 0xee:
bb = 1;
break;
case 0xed:
bb = 2;
break;
case 0xeb:
bb = 3;
break;
case 0xe7:
bb = 4;
break;
case 0xde:
bb = 5;
break;
case 0xdd:
bb = 6;
break;
case 0xdb:
bb = 7;
break;
case 0xd7:
bb = 8;
break;
case 0xbe:
bb = 9;
break;
case 0xbd:
bb = 0;
break;
case 0xbb: //确认
{
scan2 = 0;
scan1 = aa;
time1 = 0;
shuc();
}
break;
case 0xb7: //三角波
{
time1 = 0;
sjb();
}
break;
case 0x7e: //加
{
time1 = 0;
scan1++;
if (scan1 == 10)
{
scan1 = 0;
scan2++;
if (scan2 == 10)
scan2 = 0;
}
shuc();
}
break; //c
case 0x7d: //减
{
time1 = 0;
scan1--;
if (scan1 == -1)
{
scan1 = 9;
scan2--;
if (scan2 == -1)
scan2 = 9;
}
shuc();
}
break;
case 0x7b: //自动步进
{
time1 = 0;
zdbj();
}
break; //e
case 0x77:
time1--;
break;
}
;
if (time1 == 12)
switch (key)
{
case 0xee:
time1--;
break;
case 0xed:
time1--;
break;
case 0xeb:
time1--;
break;
case 0xe7:
time1--;
break;
case 0xde:
time1--;
break;
case 0xdd:
time1--;
break;
case 0xdb:
time1--;
break;
case 0xd7:
time1--;
break;
case 0xbe:
time1--;
break;
case 0xbd:
time1--;
break;
case 0xbb: //确认
{
time1 = 0;
scan2 = aa;
scan1 = bb;
time1 = 0;
shuc();
}
break;
case 0xb7: //三角波
{
time1 = 0;
sjb();
}
break;
case 0x7e: //加
{
scan1++;
if (scan1 == 10)
{
scan1 = 0;
scan2++;
if (scan2 == 10)
scan2 = 0;
}
shuc();
}
break; //c
case 0x7d: //减
{
time1 = 0;
scan1--;
if (scan1 == -1)
{
scan1 = 9;
scan2--;
if (scan2 == -1)
scan2 = 9;
}
shuc();
}
break;
case 0x7b: //自动步进
{
time1 = 0;
zdbj();
}
break; //e
case 0x77:
time1--;
break;
}
} while (1);
}
```
以上是基于51单片机的数控稳压电源设计的解决方案。通过控制输出和显示部分,实现了对电源电压的控制和显示功能。
本次数控稳压电源设计基于51单片机,通过控制输出来实现对电源的电压控制和显示功能。主要的设计流程如下:
1. 主要输出部分:通过设置4X4矩阵键盘,可以任意置数、加减和自动步进,实现输出波形的控制。
2. 预置数部分:通过拨码开关来预置电压值。
3. 显示部分:通过51单片机对两位数码管进行动态扫描,实现电压值的显示。
以下是代码实现部分:
```c
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar aa, bb, cc, dd, jj, ii, jjj, iii, key, j;
uchar time1 = 0;
sbit led1 = P2^0;
sbit led2 = P2^1;
sbit ce = P2^4;
#define timer0_count 0xfc18 //定时器初值,设置time0 1/1000秒中断一次
const seg[10] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90}; //数码管的显示
const seg_point[10] = {0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x10}; //有小数点的数码管显示
uchar scan1; //用来分别显示2个数码管
uchar scan2;
uchar counter[2] = {0xf1, 0xf2};
uchar vout = 0; //j_片选,vout_电压输出
static void timer0_initialize(void) //timer0的初始化
{
EA = 0; //中断控制器IE--停止接受中断
TR0 = 0; //停止计时
TMOD = 0x01; //设置工作方式为1
TL0 = (timer0_count & 0x00ff);
TH0 = (timer0_count >> 8); //设置time0 初值
PT0 = 1; //设置timer0高优先级
ET0 = 1; //允许timer0中断
TR0 = 1; //开始计时
EA = 1; //开所有中断
}
void delay(uint t) //tms的延时
{
uchar i;
uint j;
for (j = 0; j < t; j++)
for (i = 0; i < 40; i++)
;
}
void shuc(void)
{
uchar nn;
vout = 2 * (scan2 * 10 + scan1); //输出的数字量
P1 = vout;
for (nn = 0; nn < 250; nn++)
;
nn = 0; //输出是存在D/A转换时间差所以要延时
}
void shaom(void)
{
P3 = 0x0f; //扫描是否有按键按下
if ((P3 & 0x0f) != 0x0f)
dd = 0;
else
dd = 1;
}
void zdbj(void) //自动步进
{
uchar rr;
jj = scan2;
ii = scan1;
shaom();
for (; jj < 10; jj++)
{
for (; ii < 10; ii++)
{
if (dd)
{
scan1 = ii;
scan2 = jj;
shuc();
for (rr = 0; rr < 250; rr++)
{
shaom();
if (dd)
delay(70);
else
break;
}
if (jj == 9 && ii == 9)
{
ii = 0;
jj = 0;
}
}
else
{
jj = 10;
ii = 10;
}
}
ii = 0;
}
jj = 0;
shaom();
for (; dd == 0;)
shaom();
}
void sjb(void) //三角波
{
uchar max;
max = vout;
shaom();
for (; dd;)
{
for (iii = 0; iii < max; iii = iii + 2)
{
P1 = iii;
shaom();
delay(7);
if (dd == 0)
break;
}
if (dd == 0)
break;
for (; iii > 0; iii = iii - 2)
{
P1 = iii;
shaom();
delay(10);
if (dd == 0)
break;
}
if (dd == 0)
break;
}
P1 = max;
shaom();
for (; dd == 0;)
shaom();
}
unsigned char keyscan(void) //键盘扫描函数,使用行列反转扫描法
{
unsigned char cord_h, cord_l; //行列值中间变量
P3 = 0x0f; //行线输出全为0
cord_h = P3 & 0x0f; //读入列线值
if (cord_h != 0x0f) //先检测有无按键按下
{
delay(70); //去抖
if ((P3 & 0x0f) != 0x0f)
{
cord_h = P3 & 0x0f; //读入列线值
P3 = cord_h | 0xf0; //输出当前列线值
cord_l = P3 & 0xf0; //读入行线值
while ((P3 & 0xf0) != 0xf0) //等待松开并输出
{
time1 = time1 + 1;
return (cord_h + cord_l); //键盘最后组合码值
}
}
}
return (0); //返回该值
}
void timer0_isr(void) interrupt 1 //timer0中断
//用于LED数码管的动态显示
{
TR0 = 0; //停止时钟0
P2 = counter[j];
switch (j)
{
case 0:
P0 = seg[scan1];
break;
case 1:
P0 = seg_point[scan2];
break;
default:
break; //j为其他情况是跳出循环
}
j++;
if (j == 2)
j = 0;
TL0 = (timer0_count & 0x00ff);
TH0 = (timer0_count >> 8); //设置time0 初值
TR0 = 1; //开时钟
}
void main(void)
{
ce = 0;
delay(5);
scan1 = (P3 / 2) % 10;
scan2 = P3 / 20;
ce = 1;
delay(5);
shuc();
timer0_initialize(); //定时器初始化用于LED显示
do
{
key = keyscan();
if (time1 == 1)
switch (key)
{
case 0xee:
aa = 1;
break;
case 0xed:
aa = 2;
break;
case 0xeb:
aa = 3;
break;
case 0xe7:
aa = 4;
break;
case 0xde:
aa = 5;
break;
case 0xdd:
aa = 6;
break;
case 0xdb:
aa = 7;
break;
case 0xd7:
aa = 8;
break;
case 0xbe:
aa = 9;
break;
case 0xbd:
aa = 0;
break;
case 0xbb:
time1--;
break;
case 0xb7: //三角波
{
time1 = 0;
sjb();
}
break;
case 0x7e: //加
{
time1 = 0;
scan1++;
if (scan1 == 10)
{
scan1 = 0;
scan2++;
if (scan2 == 10)
scan2 = 0;
}
shuc();
}
break; //c
case 0x7d: //减
{
time1 = 0;
scan1--;
if (scan1 == -1)
{
scan1 = 9;
scan2--;
if (scan2 == -1)
scan2 = 9;
}
shuc();
}
break;
case 0x7b: //自动步进
{
time1 = 0;
zdbj();
}
break; //e
case 0x77:
time1--;
break;
}
if (time1 == 2)
switch (key)
{
case 0xee:
bb = 1;
break;
case 0xed:
bb = 2;
break;
case 0xeb:
bb = 3;
break;
case 0xe7:
bb = 4;
break;
case 0xde:
bb = 5;
break;
case 0xdd:
bb = 6;
break;
case 0xdb:
bb = 7;
break;
case 0xd7:
bb = 8;
break;
case 0xbe:
bb = 9;
break;
case 0xbd:
bb = 0;
break;
case 0xbb: //确认
{
scan2 = 0;
scan1 = aa;
time1 = 0;
shuc();
}
break;
case 0xb7: //三角波
{
time1 = 0;
sjb();
}
break;
case 0x7e: //加
{
time1 = 0;
scan1++;
if (scan1 == 10)
{
scan1 = 0;
scan2++;
if (scan2 == 10)
scan2 = 0;
}
shuc();
}
break; //c
case 0x7d: //减
{
time1 = 0;
scan1--;
if (scan1 == -1)
{
scan1 = 9;
scan2--;
if (scan2 == -1)
scan2 = 9;
}
shuc();
}
break;
case 0x7b: //自动步进
{
time1 = 0;
zdbj();
}
break; //e
case 0x77:
time1--;
break;
}
;
if (time1 == 12)
switch (key)
{
case 0xee:
time1--;
break;
case 0xed:
time1--;
break;
case 0xeb:
time1--;
break;
case 0xe7:
time1--;
break;
case 0xde:
time1--;
break;
case 0xdd:
time1--;
break;
case 0xdb:
time1--;
break;
case 0xd7:
time1--;
break;
case 0xbe:
time1--;
break;
case 0xbd:
time1--;
break;
case 0xbb: //确认
{
time1 = 0;
scan2 = aa;
scan1 = bb;
time1 = 0;
shuc();
}
break;
case 0xb7: //三角波
{
time1 = 0;
sjb();
}
break;
case 0x7e: //加
{
scan1++;
if (scan1 == 10)
{
scan1 = 0;
scan2++;
if (scan2 == 10)
scan2 = 0;
}
shuc();
}
break; //c
case 0x7d: //减
{
time1 = 0;
scan1--;
if (scan1 == -1)
{
scan1 = 9;
scan2--;
if (scan2 == -1)
scan2 = 9;
}
shuc();
}
break;
case 0x7b: //自动步进
{
time1 = 0;
zdbj();
}
break; //e
case 0x77:
time1--;
break;
}
} while (1);
}
```
以上是基于51单片机的数控稳压电源设计的解决方案。通过控制输出和显示部分,实现了对电源电压的控制和显示功能。
为您推荐其他供应商的行业解决方案
免责声明:本网站部分内容来源互联网,如权利人发现存在侵权信息,请及时与本站联系删除。
供应商:
敦晨科技
所在区域: 全国
敦晨科技是一家专注于硬件研发的公司,拥有12年以上的单片机硬件开发经验。我们擅长于51/STM32/MSP430/AVR等单片机设计,并提供电路设计方案、智能浇花系统、智能家居、物联网、传感器、机器人、蓝牙、红外传感器、台灯电路、智能车、RFID射频模块电路、超声波传感器、智能水表、防盗系统、仿真、激光传感器、角度传感器、监控系统、霍尔传感器、温湿度传感器、红外遥控、声音传感器、温度传感器、水位传感器、指纹识别、电机、无线充电、倒车系统、幸运转盘原理图、WIFI、篮球积分器电路设计、智能手环、万年历源码、智能电表、压力传感器、湿度传感器、智能手表、台灯源码、空气质量传感器、气压传感器、门禁系统、智能水杯、智能家电、测距传感器、汽车传感器、智能农业、电池供电电路、蓝牙控制、太阳能充电、充电器方案、电路、开发板、万年历电路、Modbus、proteus仿真、数据采集、智能插座、光电开关、proteus仿真电路、wifi模块、电源设计、远程监控、干手器控制板原理图、pm2.5传感器、电子琴电路、tp4056电路、防盗报警系统、音乐盒项目方案等服务。
我们提供多种解决方案,如基于51单片机的智能台灯节能灯热释人体自动感应照明灯、基于51单片机的蓝牙音箱设计、基于51单片机的灯光控制系统设计、基于51单片机的多功能家庭红外报警器设计、基于51单片机的GSM密码开关设计、基于51单片机的RFID材料监控系统设计、基于51单片机的老人防跌倒设计主从机设计、基于51单片机的语音自动播报留言箱设计、毕业设计-51单片机射频RFID卡考勤人数计数统计系统、51单片机智能浇花浇水系统花卉灌溉土壤湿度检测、毕业设计-51单片机音乐喷泉频谱彩灯多功能音乐盒播放器等。
敦晨科技致力于为电子相关专业的大学生提供优质的设计资料和解决方案,帮助他们在未来的职业道路上取得成功。我们期待与您合作,共创美好未来!