51单片机控制继电器制冷片求助!!!

求助!!!!我想用74LS165 IC达到并入串出,然后在用51单片机接收并控制8个灯来显示。我写的程序如下求,_百度知道
求助!!!!我想用74LS165 IC达到并入串出,然后在用51单片机接收并控制8个灯来显示。我写的程序如下求,
程序运失败。用延时可以,但定时器就不行了,我想问的是:我定时方式错了,还本来就不可以用定时器。#include&reg51.h& //头文件#define uchar unsigned char //宏定义,为方便编程#define uint unsigned int#define LED P1 //宏定义,将P1口定义为LEDsbit LOAD=P3^2; //定义P3.2为数据置入位 unsigned char value=0;void Delay(time)
//延时器{
while(time!=0)
time--; }void
//定时初始化,及串行接收初始化{
TMOD=0x01;
TH0=()/256;
TL0=()%256;
// LOAD=0;
while(1);}void
serial() interrupt 1
//定时器运行内容{趴休龄旧绲搅榴些庐氓
TMOD=0x01;
TH0=()/256;
TL0=()%256;
Delay(200);
while(!RI)
value=SBUF;
#include&reg51.h& //头文件//#define uchar unsigned char //宏定义,为方便编程//#define uint unsigned intsbit LED =P1 ;//宏定义,将P1口定义为LEDsbit LOAD=P3^2; //定义P3.2为数据置入位 void Delay(time){
while(time!=0)
time--; }void init() {
ES=1; }//char code SST516[3] _at_ 0x003b;刺釉拜猎之捞瓣哟抱瓢 //仿真器入口main() //主函数{
unsigned char value=0;
init(); //串口初始化
LOAD=0; //74165并口端载入数据
Delay(200); //延迟
LOAD=1; //将置数据位拉高
while(!RI); //若没接收够8位串行数据则等待
RI=0; //接收完毕,标志位清0
value=SBUF; //读取数据
P1= //赋给P1,驱动LED
Delay(400); //延迟,完毕后进行下一次并行数据载入
提问者采纳
TR0=1;这个不在初始化先开吗?定时器能开始计时?你懂得~~
忘了,呵呵,不过我试了,还是不行
定时器1波特率呢我说错了。。
谢谢你的帮助。我自己实在搞不定了。如果可以的话请大家帮我写下这个程序,但是要用上定时器。谢谢!
木有分。。。你懂得?
我现在没什么分,只能出这么多了,能帮我写一个,本人感激涕零
你这么写肯定是不对的,延时也不可能接收的到的,波特率完全没有。。。你给我看下你延时能接收到的程序吧~~
在补充时里
我先去吃饭,你先好好看下串口是怎么设置的
给你发个串口的
提问者评价
大声说谢谢
其他类似问题
51单片机的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁树莓派打造视频监控机器人Verybot...
根据自己的一些从业经验,将这些系统设计时针对波特率自适应问题做一些阐述和分享..
【求助】51单片机直流电机转速控制,程序问题在哪?
5&天前&nbsp
程序如下:#include&reg51.h&
#define uchar unsigned char
#define uint unsigned int
const uchar tab_hi[]& & & & = {0x81,0xf7,0xf7,0x81,0xff,0xbd,0x81,0xbd};& & & & & & & & & & & & //HI default
const uchar tab_zheng[] = {0x7e,0x7e,0x06,0x7e,0x00,0x76,0x76,0x76};& & & & & & & && &&&//zheng
const uchar tab_fang[]& & & & = {0x7f,0x9f,0x6f,0xb1,0xea,0xea,0xb2,0x7a};& & & & & & & && &&&//fang
const uchar tab_stop[]&&= {0xff,0xff,0x00,0xee,0xee,0xee,0xf5,0xfb};& & & & & & & && &&&//P
uchar PWM1=0& &//PWM greater ,speed faster,default 0.5 ms
uchar PWM2=0x34;
uchar ENA;
uchar count0=0;
uchar count1=0;
const uchar tab[] & & & && &&&= {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};& & & & & & & & & & & &&&//P2
sbit dir & & & & = P1^0;& & & & & & & & & & & & //direction
sbit faster = P1^1;& & & & & & & & & & & & //faster
sbit lower&&= P1^2;& & & & & & & & & & & & //lower
sbit st& & & && &&&= P1^3;& & & & & & & && &&&//start or stop
sbit P3_6 = P3^6;
sbit P3_7 = P3^7;
void delay(uint n)& & & & & & & & & & & & & & & & & & & &&&//delay n ms
& & & & uchar i,j;
& & & & for(i=n;i&0;i--)
& & & & & & & & for(j=110;j&0;j--);& & & & & & & && && & //delay 1ms
void init(void)
& & & & TMOD = 0x11;& &// t1 work on mode 1,t0 work on mode 1
& & & & TH0 =0& & & && & //initial value fc66, means 1 ms
& & & & TL0 =0x66;
& & & & TH1 =PWM1;
& & & & TL1 =PWM2;
& & & & EA = 1;
& & & & ET0=1;
& & & & ET1=1;
& & & & TR0 =1;& && & //T0 START
void timer0() interrupt 1& & //timer 0 interrupt
& & & & TH0=0& &&&//reload the 1 ms value to the timer 0
& & & & TL0=0x66;
& & & & if(count0&100)
& & & & & & & & count0++;
& & & & else
& & & & & & & & count0=0;
& & & & & & & & ENA=1;
& & & & & & & & TH1=PWM1;
& & & & & & & & TL1=PWM2;
& & & & & & & & TR1=1;& & & & & & & && &//T1 START
void timer1() interrupt 3& & //timer 1 interrupt 3
& & & & TH1=PWM1;& & & & & & & & & & & & & & & & // reload the value
& & & & TL1=PWM2;
& & & & if(count1&100)
& & & & & & & & count1++;
& & & & else
& & & & & & & & TR1=0;& && && &//T1 stop
& & & & & & & & ENA=0;
& & & & & & & & count1=0;
void main(void)
& & & & uchar i,j,change=0,direction=0;
& & & & P1 = 0& & & & & & & & & & & & & & & & & & & && &// SET 1 prepare to read data from P1 port
& & & & P3_6 = 1;& && && && && && && &// the default state of motor is stop
& & & & P3_7 = 1;
& & & & p = tab_& & & & & & & & & & & & & & & & & & & && &//initiated the 8*8 led, show HI
& & & & init();
& & & & while(1)
& & & & & & & & if(dir==0)& & & & & & & & & & & && && &//dir = change the direction of motor
& & & & & & & & {
& & & & & & & & & & & & delay(10);& & & & & & & && && &//delay for debouncing
& & & & & & & & & & & & if(dir==0)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & direction = ~
& & & & & & & & & & & & & & & & if(direction==0)
& & & & & & & & & & & & & & & & {
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & & & & & & & & & P3_6=1;
& & & & & & & & & & & & & & & & & & & & P3_7=ENA;
& & & & & & & & & & & & & & & & & & & & p =tab_
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & else
& & & & & & & & & & & & & & & & {
& & & & & & & & & & & & & & & & & & & & P3_6=ENA;
& & & & & & & & & & & & & & & & & & & & P3_7=1;
& & & & & & & & & & & & & & & & & & & & p=tab_
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & }
& & & & & & & & & & & & while(!dir);
& & & & & & & & & & & & delay(10);
& & & & & & & & & & & & while(!dir);
& & & & & & & & }
& & & & & & & &
& & & & & & & &
& & & & & & & & if(faster==0)& & & & & & & &&&// speed up
& & & & & & & & {
& & & & & & & & & & & & delay(10);
& & & & & & & & & & & & if(faster==0)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & PWM1=0&&//0.05ms
& & & & & & & & & & & & & & & & PWM2=0xd2;
& & & & & & & & & & & & }
& & & & & & & & & & & & while(!faster);
& & & & & & & & & & & & delay(10);
& & & & & & & & & & & & while(!faster);
& & & & & & & & }
& & & & & & & &
& & & & & & & &
& & & & & & & & if(lower==0)& & & & & & & & & & & & //lower = speed down
& & & & & & & & {
& & & & & & & & & & & & delay(10);
& & & & & & & & & & & & if(lower==0)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & PWM1=0& &//0.95 ms
& & & & & & & & & & & & & & & & PWM2=0x94;
& & & & & & & & & & & & }
& & & & & & & & & & & & while(!lower);
& & & & & & & & & & & & delay(10);
& & & & & & & & & & & & while(!lower);
& & & & & & & & }
& & & & & & & &
& & & & & & & & if(st==0)& & & & & & & & & & & & //st = start the motor or stop the motor
& & & & & & & & {
& & & & & & & & & & & & delay(10);
& & & & & & & & & & & & if(st==0)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & change = ~
& & & & & & & & & & & & & & & & if(change==0)& && &&&//stop t0he motor
& & & & & & & & & & & & & & & & {
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & & & & & & & & & P3_6 = 1;
& & & & & & & & & & & & & & & & & & & & P3_7 = 1;
& & & & & & & & & & & & & & & & & & & & PWM1 = 0& & //0.5 ms
& & & & & & & & & & & & & & & & & & & & PWM2 = 0x34;
& & & & & & & & & & & & & & & & & & & & p = tab_
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & else& && && && && & // start the motor
& & & & & & & & & & & & & & & & {
& & & & & & & & & & & & & & & & & & & & P3_6 = 1;
& & & & & & & & & & & & & & & & & & & & P3_7 = ENA;
& & & & & & & & & & & & & & & & & & & & p = tab_
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & }
& & & & & & & & & & & & while(!st);
& & & & & & & & & & & & delay(10);
& & & & & & & & & & & & while(!st);
& & & & & & & & }
& & & & & & & & & & & & & & & &
& & & & & & & & for(i=0,j=0;i&8;i++)
& & & & & & & & {
& & & & & & & & & & & & P2 = tab[j++];& & & &&&// enable
& & & & & & & & & & & & P0 = *p++;& & & & & & & & //zi xing ma& & & &&&
& & & & & & & & & & & & delay(2);
& & & & & & & & & & & & if(j==8)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & j=0;
& & & & & & & & & & & & & & & & p=p-8;
& & & & & & & & & & & & & & & & //P0=0
& & & & & & & & & & & & & & & & //P2=0x00;
& & & & & & & & & & & & }
& & & & & & & & }
实际调试的时候,电机速度不变,不知道是什么原因,求大家分析一下
发表于 5&天前
程序的主要思想是利用T0和T1定时器,都工作在模式1,16位定时器,T0产生1ms定时来将ENA拉高(ENA用来驱动直流电机),通过控制T1的初值来控制电机的转速。但是下到硬件上的时候,速度没有明显改变啊。
发表于 5&天前
P3_6和P3_7用来驱动直流电机,P1_0,P1_1,P1_2,P1_3接4个按键,分别为电机转向,电机加速,电机减速,电机启动或停止。P0和P2口驱动8*8点阵,都为低时LED亮。
大概就是这样,按加速键和减速键不能调节电机速度,程序的问题到底在哪呢?
发表于 5&天前
唉,只能猜测你的驱动是桥式驱动了;
ENA为脉冲信号,但是没有随时更新给P3.6、P3.7,根据你的程序,ENA只在方向按钮按下时才会更新给P3.6、P3.7,所以你的电机并没有处在脉冲调宽的工作状态,而是处于全速状态,因为驱动 没有被调制;
提问最好尽量描述自己的思路,控制细节,这样别人才能很快找到你的问题;要别人来猜你的设计和思路,实际是在浪费别人的时间
发表于 4&天前
唉,只能猜测你的驱动是桥式驱动了;
ENA为脉冲信号,但是没有随时更新给P3.6、P3.7,根据你的程序,ENA只 ...
我是用H桥来驱动直流电机的.感谢点醒了我
站长推荐 /2
Powered by基于51单片机控制的电子秤设计与实现--update_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
基于51单片机控制的电子秤设计与实现--update|基​于1​单​片​机​控​制​的​电​子​秤​设​计​与​实​现​-​-​u​p​d​a​t​e
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢求助,51单片机按键控制数码管显示,以及更改输出PWM占空比
[问题点数:40分,无满意结帖,结帖人daweiyan18]
求助,51单片机按键控制数码管显示,以及更改输出PWM占空比
[问题点数:40分,无满意结帖,结帖人daweiyan18]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。

我要回帖

更多关于 单片机控制继电器 的文章

 

随机推荐