main.c

来自「蓝津运动控制卡(ADuC842)开关量输入源程序」· C语言 代码 · 共 76 行

C
76
字号
#include <stdio.h>#include <stdlib.h>#include "aduc842.h"#include "port.h"#include "global.h"
sbit endi = P3^5;unsigned char xdata Relay _at_ RelayPort;void RelayOutput(unsigned char channel, bit put){		unsigned char temp = put;	if (put)		Relay |= (1 << channel) ;     //输出1	else 		Relay &= ~(1 << channel) ;    //输出0	
}
  void Readinput(void)
{
  unsigned char temp;
  endi = 0;              //控制P0口为低电平,开启开关量输入
  for(temp = 0;temp < 1; temp++);
  temp = P0;            //读入开关量输入结果
  printf("%x\n", temp);
}
	void InitSerial (void)   //初始化串口为9600bps{	SCON = 0x50;	PCON &= 0x7F;    	TMOD &= 0xCF;	TMOD |= 0x20;     	TH1 = 0xC9;	TR1 = 1;	TI = 1;}void InitRelay(){	Relay = 0x00;}void main(void){	unsigned char ch, output;	PLLCON = 0x00;  	CFG842 = 0x41;  	InitSerial();	InitRelay();	puts("\n\nThis is a sample of relay control\n\n");	while (1)	{		puts("input relay channel   :(0~7)");		ch = getchar();		putchar('\n');		if (ch < 48 || ch > 55)		{			puts("input error\n");			continue;		}		puts("input output status:(0,1)");		output = getchar();		putchar('\n');		if (output < 48 || output > 49)		{			puts("input error\n");			continue;			}
		Readinput();		RelayOutput(ch - 48, output - 48);	}}

⌨️ 快捷键说明

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