欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1499|回復: 3
收起左側

各位大佬幫我看一下這程序哪里出錯了,在51開發板上下載運行沒有聲音?

[復制鏈接]
ID:795795 發表于 2020-7-2 16:45 來自觸屏版 | 顯示全部樓層 |閱讀模式
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uint a=0;
sbit fm=P1^4;
sbit int0=P3^2;
sbit int1=P3^3;
uchar timeh,timel;
uchar code sb[]={
0x54,0x32,0x52,0x88,0x64,0x84,0x58,0x54,0x12,0x22,0x34,0x22,0x12,0x28,0x00,0x00,
0x54,0x32,0x52,0x86,0x72,0x64,0x84,0x58,0x54,0x22,0x32,0x46,0xf2,0x18,0x00,0x00,
0x64,0x84,0x88,0x74,0x62,0x72,0x88,0x62,0x72,0x82,0x62,0x62,0x52,0x32,0x12,0x28,0x00,0x00,
0x54,0x32,0x52,0x86,0x72,0x64,0x84,0x58,0x54,0x22,0x32,0x46,0xf2,0x18,0x00,0x00,
0x54,0x32,0x52,0x88,0x64,0x84,0x58,0x54,0x12,0x22,0x34,0x22,0x12,0x28,0x00,0x00,
0x54,0x32,0x52,0x86,0x72,0x64,0x84,0x58,0x54,0x22,0x32,0x46,0xf2,0x18,0x00,0x00
};
uchar code chuzhi[]={
0xff,0xff,
0xFC,0x43,//C÷1-7
0xFC,0xad,
0xFd,0x0a,
0xFD,0x34,
0xFD,0x82,
0xFD,0xc8,
0xFE,0x06,
0xFe,0x21,//
0xFe,0x56,
0xFe,0x85,
0xFe,0x9a,
0xFe,0xc1,
0xFe,0xe4,
0xFf,0x03,
0xFc,0x0c
//0xF8,0x18,//°1-7
};
void timer0() interrupt 1
{
TH0=timeh;
TL0=timel;
fm=~fm;
}
void delay(uint z)
{ uint y;
for(z;z>0;z--)
for(y=19000-a;y>0;y--);
}
void delay1(uint z)
{uint y;
for(z;z>0;z--)
for(y=112;y>0;y--);
}
void main()
{
uint temp;
uint lightTemp;
uchar i=0;
uchar jp;
IT0=1;//INT0
IT1=1; //INT1
TMOD=0x01;
IE=0x87;
while(1)
{
temp=sb[i];
if(temp==0xff)
break;
jp=temp/16;
lightTemp=(1<<jp)-1;
P2=~lightTemp/0x100;
P0=~lightTemp%0x100;
if(jp!=0)
{
timeh=chuzhi[jp*2];
timel=chuzhi[jp*2+1];
TR0=1;
}
else
{
TR0=0;
fm=1;
}
delay(temp%16);
TR0=0;
fm=1;
delay1(5);
i++;
}
TR0=0;
fm=1;
}
void delay_ms(uint a){
int i,j;
for(i=a;i>=0;j--){}
}
void INT0_svr(void) interrupt 0
{
delay_ms(10);
if(int0==0){
a+=2000;
if(a>18000)a=0;
}
}
void INT1_svr(void) interrupt 2
{
delay_ms(10);
if(int1==0){
a-=2000;
if(a<=0)a=0;}
}
回復

使用道具 舉報

ID:636538 發表于 2020-7-3 09:34 | 顯示全部樓層
#include "reg52.h"                         //此文件中定義了單片機的一些特殊功能寄存器

typedef unsigned int u16;          //對數據類型進行聲明定義
typedef unsigned char u8;

sbit led=P2^0;         //定義P20口是led


/*******************************************************************************
* 函 數 名         : Timer0Init
* 函數功能                   : 定時器0初始化
* 輸    入         : 無
* 輸    出         : 無
*******************************************************************************/
void Timer0Init()
{
        TMOD|=0X01;//選擇為定時器0模式,工作方式1,僅用TR0打開啟動。

        TH0=0XFC;        //給定時器賦初值,定時1ms
        TL0=0X18;       
        ET0=1;//打開定時器0中斷允許
        EA=1;//打開總中斷
        TR0=1;//打開定時器                       
}

/*******************************************************************************
* 函 數 名       : main
* 函數功能                 : 主函數
* 輸    入       : 無
* 輸    出             : 無
*******************************************************************************/
void main()
{       
        Timer0Init();  //定時器0初始化
        while(1);               
}

/*******************************************************************************
* 函 數 名         : void Timer0() interrupt 1
* 函數功能                   : 定時器0中斷函數
* 輸    入         : 無
* 輸    出         : 無
*******************************************************************************/
void Timer0() interrupt 1
{
        static u16 i;
        TH0=0XFC;        //給定時器賦初值,定時1ms
        TL0=0X18;
        i++;
        if(i==1000)
        {
                i=0;
                led=~led;       
        }       
}
回復

使用道具 舉報

ID:636538 發表于 2020-7-3 09:28 | 顯示全部樓層
你在定時器0對應的中斷ET0=1;EA=1;這個中斷允許沒有打開,你的外部中斷EX1=1;外部中斷允許沒有打開,而且你的中斷初始化寫的這么讓人別扭
回復

使用道具 舉報

ID:748788 發表于 2020-7-2 22:07 | 顯示全部樓層
如果還處于抄別人程序的階段,建議從簡單的開始抄起。一口吃個胖子,也消化不了。
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表