| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 548 人关注过本帖
标题:帮忙找一下哪个地方错了
只看楼主 加入收藏
冬2509102
Rank: 2
等 级:论坛游民
帖 子:32
专家分:33
注 册:2013-9-14
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
帮忙找一下哪个地方错了
程序代码:
//stc89c52
#include "reg51.h"
#include"74HC595.H"

#define Key P1
#define Out1 P3
#define Out2 P2
//#define indicator P0

#define uint unsigned int
#define uchar unsigned char



#define PowerUP     0x200                                                        //上电
#define PlayAddress 0xe00                                                          //播放地址
#define PlayR       0xf00                                                          //播放开始
#define Stop        0x300                                                          //停止操作

sfr P4=0xe8;//STC单片机

sbit KeyA=P1^0;                                                                    //8个手掌按键
sbit KeyB=P1^1;
sbit KeyC=P1^2;
sbit KeyD=P1^3;
sbit KeyE=P1^4;
sbit KeyF=P1^5;
sbit KeyG=P1^6;
sbit KeyH=P1^7;

sbit ModeKey=P3^5;    

sbit SS   = P4^0;//语音芯片控制端
sbit MOSI = P4^1;
sbit SCLK = P4^2;
sbit ISD_Int  = P4^3;                                                            //模式按键

//sbit SS=P3^7;                                                                    //三个声音控制输出口
//sbit SCLK=P3^4;
//sbit MOSI=P3^6;
sbit LOut1=P3^1;

sbit LOut2=P3^0;

sbit Out1LED1=P2^0;                                                                //按键A~F灯光输出控制端口
sbit Out1LED2=P2^1;
sbit Out1LED3=P2^2;
sbit Out1LED4=P2^3;
sbit Out1LED5=P2^4;
sbit Out1Red=P2^5;
sbit Out1Green=P2^6;
sbit Out1Blue=P2^7;
sbit Out1Yellow=P3^2;

bit Sound1=0,Sound2=0,Sound3=0,Sound4=0,Sound5=0,Sound6=0,Sound7=0,Sound8=0;
uchar K1=0,K2=0,K3=0,K4=0,K5=0,K6=0,LED=0x80,Mode=0;
uint code PlayAddressTeam[64]={        0x00,0x97,0x179,0x2D2,0x07,0xF4,0x1D9,0x2B7,
                                    0x16,0xB3,0x196,0x2F2,0x24,0x111,0x1F5,0x2D3,
                                    0x30,0xD0,0x1A9,0x31E,0x42,0x12F,0x211,0x2F0,
                                    0x46,0xEB,0x1E2,0x33B,0x5F,0x14B,0x22D,0x30C,
                                    0x56,0x108,0x210,0x359,0x7D,0x167,0x249,0x325,
                                    0x69,0x123,0x226,0x395,0x9B,0x181,0x265,0x342,
                                    0x74,0x13F,0x267,0x3CB,0xB9,0x19C,0x280,0x35B,
                                    0x91,0x15D,0x2A3,0x3E9,0xD6,0x1BB,0x28C,0x376};

void Delay10ms()
{
    unsigned char a,b,c;
    for(c=1;c>0;c--)
        for(b=38;b>0;b--)
            for(a=130;a>0;a--);
}

void WriteCategory(uint abc,def)                                                  //写入24位数据
{
    uint m,n,j;
    uchar i;
    SS=1;
    SCLK=0;
    MOSI=0;
    n=abc;
    m=def;
    SS=0;
    for(i=0;i<12;i++)
    {
        SCLK=0;
        j=m&0x001;
        if(j==0)MOSI=0;
        else MOSI=1;
        SCLK=1;
        m=m>>1;
    }
    for(i=0;i<12;i++)
    {
        SCLK=0;
        j=n&0x001;
        if(j==0)MOSI=0;
        else MOSI=1;
        SCLK=1;
        n=n>>1;
    }
    SS=1;
}

void PowerUpCategory(void)                                                       //上电
{
    WriteCategory(PowerUP,0);
    Delay10ms();
    Delay10ms();
    Delay10ms();
    Delay10ms();
}

void ModeKeyCategory()                                                           //模式选择
{
    ModeKey=1;
    if(ModeKey==0)
    {
        Delay10ms();
        if(ModeKey==0)
        {
            LED=LED>>1;
            Mode=Mode+8;
        }
        if(Mode>56)Mode=0;
        if(LED==0)LED=0x80;
        while(ModeKey==0);
    }
    HC595_Play(LED);
    //indicator=LED;
}

void PlayCategory(uint cp)                                                       //播放
{
    WriteCategory(Stop,0);
    Delay10ms();
    Delay10ms();
    Delay10ms();
    WriteCategory(PlayAddress,cp);                                               //写地址
    WriteCategory(PlayR,0);                                                      //写播放指令
    Delay10ms();
}

void Timer0int()interrupt 1
{
    TH0=60;
    TL0=171;

    if(KeyA==1)
    {
        K1++;
        if(K1>=40)K1=0;
    }
    if(KeyB==1)
    {
        K2++;
        if(K2>=40)K2=0;
    }
    if(KeyC==1)
    {
        K3++;
        if(K3>=40)K3=0;
    }
    if(KeyD==1)
    {
        K4++;
        if(K4>=40)K4=0;
    }
    if(KeyE==1)
    {
        K5++;
        if(K5>=40)K5=0;
    }
    if(KeyF==1)K6++;
}

void Key1_6Act(void)
{
    if(KeyA==1)                                                                    //按键1动作
    {
        if(K1<=20)Out1LED1=1;
        else Out1LED1=0;
        if(Sound1==0)
        {
            PlayCategory(PlayAddressTeam[Mode+0]);
        }
        Sound1=1;
    }
    else if(KeyA==0)
    {
        Out1LED1=0;
        Sound1=0;
    }

    if(KeyB==1)                                                                    //按键2动作
    {
        if(K2<=20)Out1LED2=1;
        else Out1LED2=0;
        if(Sound2==0)
        {
            PlayCategory(PlayAddressTeam[Mode+1]);
        }
        Sound2=1;
    }
    else if(KeyB==0)
    {   
        Out1LED2=0;
        Sound2=0;
    }

    if(KeyC==1)                                                                    //按键3动作
    {
        if(K3<=20)Out1LED3=1;
        else Out1LED3=0;
        if(Sound3==0)
        {
            PlayCategory(PlayAddressTeam[Mode+2]);
        }
        Sound3=1;
    }
    else if(KeyC==0)
    {   
        Out1LED3=0;
        Sound3=0;
    }

    if(KeyD==1)                                                                    //按键4动作
    {
        if(K4<=20)Out1LED4=1;
        else Out1LED4=0;
        if(Sound4==0)
        {
            PlayCategory(PlayAddressTeam[Mode+3]);
        }
        Sound4=1;
    }
    else if(KeyD==0)
    {
        Out1LED4=0;
        Sound4=0;
    }

    if(KeyE==1)                                                                    //按键5动作
    {
        if(K5<=20)Out1LED5=1;
        else Out1LED5=0;
        if(Sound5==0)
        {
            PlayCategory(PlayAddressTeam[Mode+4]);
        }
        Sound5=1;
    }
    else if(KeyE==0)
    {
        Out1LED5=0;
        Sound5=0;
    }

    if(KeyF==1)                                                                    //按键6动作
    {
        if(K6<20)
        {
            Out1Red=1;
            Out1Green=0;
            Out1Blue=0;
            Out1Yellow=0;
        }
        else if((K6<40)&&(K6>=20))
        {
            Out1Red=0;
            Out1Green=1;
            Out1Blue=0;
            Out1Yellow=0;
        }
        else if((K6<60)&&(K6>=40))
        {
            Out1Red=0;
            Out1Green=0;
            Out1Blue=1;
            Out1Yellow=0;
        }
        else if((K6<80)&&(K6>=60))
        {
            Out1Red=0;
            Out1Green=0;
            Out1Blue=0;
            Out1Yellow=1;
        }
        else if(K6>=80)K6=0;
        if(Sound6==0)
        {
            PlayCategory(PlayAddressTeam[Mode+5]);
        }
        Sound6=1;
    }
    else if(KeyF==0)
    {
        Out1Red=0;
        Out1Green=0;
        Out1Blue=0;
        Out1Yellow=0;
        Sound6=0;
    }
}

void Key7_8Act(void)
{
    if(KeyG==1)                                                                    //按键7动作
    {
        Delay10ms();
        LOut1=0;
        if(Sound7==0)
        {
            PlayCategory(PlayAddressTeam[Mode+6]);
        }
        Sound7=1;
    }
    else if(KeyG==0)
    {
        LOut1=1;
        Sound7=0;
    }

    if(KeyH==1)                                                                    //按键8动作
    {
        Delay10ms();
        LOut2=0;
        if(Sound8==0)
        {
            PlayCategory(PlayAddressTeam[Mode+7]);
        }
        Sound8=1;
    }
    else if(KeyH==0)
    {
        LOut2=1;
        Sound8=0;
    }
}

main()
{
    //indicator=0x01;                                                                //模式指示灯
    Key=0xff;                                                                    //按键ABCDEFGH
    Out1=0;                                                                        //声音及串行输出
    Out2=0;                                                                        //按键1~6输出
    ModeKey=1;                                                                    //模式选择按键
    TMOD=0x01;
    ET0=1;
    EA=1;

    Delay10ms();
    Delay10ms();
    Delay10ms();
    Delay10ms();
    Delay10ms();

    Delay10ms();
    Delay10ms();
    Delay10ms();
    Delay10ms();
    Delay10ms();

    Delay10ms();
    Delay10ms();
    Delay10ms();
    Delay10ms();
    Delay10ms();

    Delay10ms();
    Delay10ms();
    Delay10ms();
    Delay10ms();
    Delay10ms();

    PowerUpCategory();
    HC595_Init();
    TR0=1;

    while(1)
    {
        ModeKeyCategory();
        Key1_6Act();
        Key7_8Act();
        //HC595_Play(LED);
    }
}
2013-10-30 09:14
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:7 
好好长长啊

DO IT YOURSELF !
2013-10-30 09:15
冬2509102
Rank: 2
等 级:论坛游民
帖 子:32
专家分:33
注 册:2013-9-14
收藏
得分:0 
程序代码:
*******************************************************************************/
#ifndef _74HC595_1_
#define _74HC595_1_

#include "reg51.h"

sbit HC595_DS   = P0^4;       //数据线    14
sbit HC595_CPla = P0^5;       //ST_cp  12
sbit HC595_CPsr = P0^6;       //SH_CP    11
sbit HC595_CR   = P0^7;

unsigned char HC595_data = 0;
void HC595_Play(unsigned char k);
void HC595_Cls();
void HC595_Init();


void HC595_Play(unsigned char k)//发送数据到并行口
{
    unsigned char i = 8;
   
        HC595_CPla = 0;
        for(i; i > 0; i--)
        {
            HC595_CPsr = 0;
            if((k & 0x01)!=0)HC595_DS = 1;
            else HC595_DS = 0;
             k >>= 1;
            HC595_CPsr = 1;     
           
        }
        HC595_CPla = 1;     //
       
//        return 1;
    }

void HC595_Cls()//寄存器及端口清零
{  
    HC595_CPla = 0;     //     ST_CP
    HC595_CR   = 0;   // 清零
    HC595_CPla = 1;    //
    HC595_CR   = 1;  //
}

void HC595_Init()//初始化全部清零
{
    HC595_DS   = 0;
    HC595_CPla = 0;
    HC595_CPsr = 0;
    HC595_CR   = 1;
    HC595_Cls();
} 

#endif
2013-10-30 09:15
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:7 
能说一下哪里有问题?啥问题?

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2013-11-03 17:47
快速回复:帮忙找一下哪个地方错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021998 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved