⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 485re.c

📁 单片机驱动的rs485读写程序--接受程序
💻 C
字号:
#include<regx52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int

uchar slave;//从机地址
uchar Light_DATA;//灯的灰度级别
uchar REV_DATA;//接收到的数据
//////////////////////////读地址码
void read_code()
{
if(P3_7==0){slave=1;}
if(P1_0==0){slave=2;}
if(P1_1==0){slave=3;}
if(P1_2==0){slave=4;}
if(P1_3==0){slave=5;}
if(P1_4==0){slave=6;}
if(P1_5==0){slave=7;}
}
////////////////初始化//////////////////
void init()
{
SCON=0xb0;
IE=0x90;
 }
/////////////////////////////////
void REV() interrupt 4 using 1
{
uchar DATA;
while(RI==0);RI=0;
DATA=SBUF;
if(RB8==1){
        if(DATA==slave){SM2=0;}
		if(DATA==0x55){Light_DATA=REV_DATA;}
          }
else{REV_DATA=DATA;SM2=1;}
} 
////////////////////////////////////////////////
void NOP(uchar N)
{uchar i;
for(i=0;i<N;i++){_nop_();}
}
//////////////////RGB灰度扫描///////////////////
void scan_Light()
{
  if(Light_DATA&0x80){P3_4=1;}else{P3_4=0;} NOP(128);
  if(Light_DATA&0x40){P3_4=1;}else{P3_4=0;} NOP(64);
  if(Light_DATA&0x20){P3_4=1;}else{P3_4=0;} NOP(32);
  if(Light_DATA&0x10){P3_4=1;}else{P3_4=0;} NOP(16);
  if(Light_DATA&0x08){P3_4=1;}else{P3_4=0;} NOP(8);
  if(Light_DATA&0x04){P3_4=1;}else{P3_4=0;} NOP(4);
  if(Light_DATA&0x02){P3_4=1;}else{P3_4=0;} NOP(2);
  if(Light_DATA&0x01){P3_4=1;}else{P3_4=0;} NOP(1);
}
////////////////////////////
void main (void)
{
read_code();
init();
while(1){
scan_Light();
        }
     }
///////////////////////////    
    
 


       
     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -