蓝天白云 发表于 2024-11-29 17:14:07

Ai8G1K08 8Pin

本帖最后由 DebugLab 于 2024-11-29 19:36 编辑

当我用P54的时候,我的串口就接收不到消息,注释掉关于P54的,现象就是好的,这是哪里有问题呢,求大佬帮助{:cry:}


#include <STC8G.H>
#include "intrins.h"

#define light_time 500
#define FOSC 11059200UL
#define BRT (65536 - FOSC / 9600 / 4)

unsigned int count = 0;
unsigned int count1 = 0;
bit busy;
char wptr;
char rptr;
char buffer;
char flag;

void Delay1000ms() //@11.0592MHz
{
    unsigned char i, j, k;

    i = 57;
    j = 27;
    k = 112;
    do
    {
      do
      {
            while (--k)
                ;
      } while (--j);
    } while (--i);
}
void UartInit(void) // 9600bps@12.000MHz串口1定时器1
{
    SCON = 0x50;
    TMOD = 0x00;
    TL1 = BRT;
    TH1 = BRT >> 8;
    TR1 = 1;
    AUXR = 0x40;

    wptr = 0x00;
    rptr = 0x00;
    busy = 0;
    ES = 1;
    EA = 1;
}

void UartSend(char dat)
{
    while (busy)
      ;
    busy = 1;
    SBUF = dat;
}
void UartSendStr(char *p)
{
    while (*p)
    {
      UartSend(*p++);
    }
}
void Time_Init() // 定时器0
{
    AUXR &= 0x7F; // 定时器时钟12T模式
    TMOD &= 0xF0; // 设置定时器模式
    TL0 = 0x91;   // 设置定时初始值
    TH0 = 0xFF;   // 设置定时初始值
    TF0 = 0;      // 清除TF0标志

    TR0 = 1;
    ET0 = 1;
    EA = 1;
}

void Timer2_Init(void) // 10微秒@11.0592MHz
{
    AUXR &= 0xFB; // 定时器时钟12T模式
    T2L = 0xF7;   // 设置定时初始值
    T2H = 0xFF;   // 设置定时初始值
    AUXR |= 0x10; // 定时器2开始计时
    IE2 = 0x04;   // 使能定时器2中断
    EA = 1;
}

void main()
{
    P3M0 = 0x00; // 准双向口
    P3M1 = 0x00;
    P5M0 = 0xFF; // 推挽输出
    P5M1 = 0x00;
    P55 = 0;

    P_SW1 = 0x40;

    UartInit();// 串口初始化
    Time_Init(); // 定时器0初始化
    // Timer2_Init(); // 定时器2初始化

    while (1)
    {

      switch (flag)
      {
      case 1:

            if (count >= light_time)
            {
                P55 = !P55; // 翻转灯状态
                //P54=!P54;
                count = 0;
            }
            // else if (count1 >= 1)
            // {
            //P54 = !P54; // 翻转蜂鸣器状态
            //count1 = 0;
            // }
            break;

      default:
            P55 = 0;
            //P54 = 0;
            break;
      }
    }
}
void TM0_Isr() interrupt 1
{
    TL0 = 0x91; // 设置定时初始值
    TH0 = 0xFF; // 设置定时初始值
    count++;
    count1++;
}
void UartIsr() interrupt 4
{
    if (TI)
    {
      TI = 0;
      busy = 0;
    }
    if (RI)
    {
      RI = 0;
      flag = SBUF;
    }
}
void Timer2_Isr(void) interrupt 12
{
}


页: [1]
查看完整版本: Ai8G1K08 8Pin