我在显示7段上显示的40个值时遇到问题(40个组件74hc595级联链接。 enter image description here
我在arduino上实现我的程序,效果很好 这是我的代码:
static const byte Pattern[] = {
B00010100, // 0
B00111111, // 1
B10011000, // 2
B00011010, // 3
B00110011, // 4
B01010010, // 5
B01010000, // 6
B00011111, // 7
B00010000, // 8
B00010010, // 9
B00010000}; // BLANK
byte HC595_DS_POS = 2; //Data pin (DS) pin location
byte HC595_SH_CP_POS = 3; //Shift Clock (SH_CP) pin location
byte HC595_ST_CP_POS = 4; //Store Clock (ST_CP) pin location
void IE74595_Out(uint8_t *p, unsigned char n)
{
unsigned char i, j;
uint8_t b;
digitalWrite(HC595_ST_CP_POS,0);
digitalWrite(HC595_SH_CP_POS,0);
for(j=0;j<n;j++)
{
b = Pattern[*(p+n-j-1)]; // Lay byte cao nhat truoc
for(i=0;i<8;i++)
{
digitalWrite(HC595_SH_CP_POS,0);
if(b & 0b00000001)
{
digitalWrite(HC595_DS_POS,1);
}
else
{
digitalWrite(HC595_DS_POS,0);
}
digitalWrite(HC595_SH_CP_POS,1);
b=b>>1; //Now bring next bit at MSB position
}
}
digitalWrite(HC595_ST_CP_POS,1);
}
void setup()
{
// put your setup code here, to run once:
pinMode(HC595_ST_CP_POS, OUTPUT);
pinMode(HC595_SH_CP_POS, OUTPUT);
pinMode(HC595_DS_POS, OUTPUT);
}
void loop() {
uint8_t Data[40]={2,5,1,3,2,1,3,6,1,9,4,8,1,7,0,5,1,2,5,6,5,4,1,4,1,8,1,3,1,9,5,6,4,5,6,2,6,1,0,2};
IE74595_Out(Data,40);
}
然后我在atmel工作室重新制作另一个节目,然后通过我的卡片中的极端刻录机和Usbasp加载它 这是我的代码:
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
static const uint8_t Pattern[] = {
0b00010100, // 0
0b00111111, // 1
0b10011000, // 2
0b00011010, // 3
0b00110011, // 4
0b01010010, // 5
0b01010000, // 6
0b00011111, // 7
0b00010000, // 8
0b00010010, // 9
0b00010000}; // BLANK
#define output_low(port,pin) port &= ~(1<<pin)
#define output_high(port,pin) port |= (1<<pin)
#define set_input(portdir,pin) portdir &= ~(1<<pin)
#define set_output(portdir,pin) portdir |= (1<<pin)
#define HC595_DS_POS PC4 //Data pin (DS) pin location
#define HC595_SH_CP_POS PC5 //Shift Clock (SH_CP) pin location
#define HC595_ST_CP_POS PC6 //Store Clock (ST_CP) pin location
#define HC595_PORT PORTC
#define HC595_DDR DDRC
void IE74595_Out(uint8_t *p, unsigned char n)
{
unsigned char i, j;
uint8_t b;
output_low(HC595_PORT,HC595_ST_CP_POS);
output_low(HC595_PORT,HC595_SH_CP_POS);
for(j=0;j<n;j++)
{
b = Pattern[*(p+n-j-1)];// Lay byte cao nhat truoc
for(i=0;i<8;i++)
{
output_low(HC595_PORT,HC595_SH_CP_POS);
if(b & 0b00000001)
{
output_high(HC595_PORT,HC595_DS_POS);
}
else
{
output_low(HC595_PORT,HC595_DS_POS);
}
output_high(HC595_PORT,HC595_SH_CP_POS);
b=b>>1;
}
}
output_high(HC595_PORT,HC595_ST_CP_POS);
}
int main(void)
{
set_output(DDRC,HC595_DS_POS);
set_output(DDRC,HC595_SH_CP_POS);
set_output(DDRC,HC595_ST_CP_POS);
uint8_t Data[40]={5,9,1,6,1,1,0,9,1,7,1,5,4,2,6,2,8,7,0,7,1,2,3,5,1,5,4,2,1,7,5,9,1,9,4,8,1,5,2,9};
while (1)
{
IE74595_Out(Data,40);
return 1;
}
}
这是我的名片 enter image description here
显示器不像arduino的显示器 我只显示最后一个值
我在中国开发了我的电子卡。
是材料的问题???
两个计划的唯一区别是: arduino上的DigitalWrite() Atmel上的Output_High()或output_Low
是DigitalWrite的实现== Output_high()还是output_Low()????
必须写下最后一条指令返回1;过了一会儿????
感谢的
答案 0 :(得分:-1)
SS(从选择)上的10K下拉电阻用于在主处理器启动时保持寄存器不以位为单位,并且SS线可能处于“浮动”且处于不确定状态。
对SPI.transfer()的调用向寄存器发送一个字节(一次一位),然后将LATCH(也称为SS或ST)线置为高电平,从而导致数据从寄存器的内部存储器传输到输出引脚。
引脚连接
Uno和类似的引脚连接: