signallight.c
来自「基于atmega128的交通信号灯控制程序」· C语言 代码 · 共 157 行
C
157 行
#include <iom128v.h>
#include <macros.h>
#include "init.h"
void IC8255_Init(void)
{
PORTG&=0xe3;
PORTE|=0x0c;
DDRA=0xff;
PORTA=0x89;
PORTG&=~BIT(0);
PORTG|=BIT(0);
PORTG|=0x1c;
PORTG&=0xef;
PORTE|=0x0c;
DDRB=0xff;
PORTB=0x89;
PORTG&=~BIT(0);
PORTG|=BIT(0);
PORTG|=0x1c;
PORTG&=0xe7;
PORTE|=0x0c;
DDRC=0xff;
PORTC=0x89;
PORTG&=~BIT(0);
PORTG|=BIT(0);
PORTG|=0x1c;
PORTG&=0xeb;
PORTE|=0x0c;
DDRF=0xff;
PORTF=0x89;
PORTG&=~BIT(0);
PORTG|=BIT(0);
PORTG|=0x1c;
}
void Signal_Light_State(unsigned char * temp)
{
PORTG&=0xe3;
PORTE&=0xf3;
DDRA=0xff;
PORTA=* temp++;
PORTG&=~BIT(0);
PORTG|=BIT(0);
PORTG|=0x1c;
PORTG&=0xe3;
PORTE|=BIT(2);
PORTE&=~BIT(3);
DDRA=0xff;
PORTA=* temp++;
PORTG&=~BIT(0);
PORTG|=BIT(0);
PORTG|=0x1c;
PORTG&=0xe7;
PORTE&=0xf3;
DDRC=0xff;
PORTC=* temp++;
PORTG&=~BIT(0); //发送写脉冲
PORTG|=BIT(0);
PORTG|=0x1c; //置CS为高电平
PORTG&=0xe7;
PORTE|=BIT(2);
PORTE&=~BIT(3);
DDRC=0xff;
PORTC=* temp++;
PORTG&=~BIT(0); //发送写脉冲
PORTG|=BIT(0);
PORTG|=0x1c; //置CS为高电平
PORTG&=0xeb;
PORTE&=0xf3;
DDRF=0xff;
PORTF=* temp++;
PORTG&=~BIT(0); //发送写脉冲
PORTG|=BIT(0);
PORTG|=0x1c; //置CS为高电平
PORTG&=0xeb;
PORTE|=BIT(2);
PORTE&=~BIT(3);
DDRF=0xff;
PORTF=* temp++;
PORTG&=~BIT(0); //发送写脉冲
PORTG|=BIT(0);
PORTG|=0x1c; //置CS为高电平
PORTG&=0xef;
PORTE&=0xf3;
DDRB=0xff;
PORTB=* temp++;
PORTG&=~BIT(0); //发送写脉冲
PORTG|=BIT(0);
PORTG|=0x1c; //置CS为高电平
PORTG&=0xef;
PORTE|=BIT(2);
PORTE&=~BIT(3);
DDRB=0xff;
PORTB=* temp++;
PORTG&=~BIT(0); //发送写脉冲
PORTG|=BIT(0);
PORTG|=0x1c; //置CS为高电平
}
void Read8255_PortC()
{
PORTG&=0xe3;
PORTE&=~BIT(2);
PORTE|=BIT(3);
DDRA=0;
PORTG&=~BIT(1); //发送读脉冲
Delay_us(20);
Portc[0]=PINA;
PORTG|=BIT(1);
PORTG|=0x1c; //置CS为高电平
PORTG&=0xe7;
PORTE&=~BIT(2);
PORTE|=BIT(3);
DDRC=0;
PORTG&=~BIT(1); //发送读脉冲
Delay_us(20);
Portc[1]=PINC;
PORTG|=BIT(1);
PORTG|=0x1c; //置CS为高电平
PORTG&=0xeb;
PORTE&=~BIT(2);
PORTE|=BIT(3);
DDRF=0;
PORTG&=~BIT(1); //发送读脉冲
Portc[2]=PINF;
PORTG|=BIT(1);
PORTG|=0x1c; //置CS为高电平
PORTG&=0xef;
PORTE&=~BIT(2);
PORTE|=BIT(3);
DDRB=0;
PORTG&=~BIT(1); //发送读脉冲
Delay_us(20);
Portc[3]=PINB;
PORTG|=BIT(1);
PORTG|=0x1c; //置CS为高电平
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?