用ICC写了个4094的程序,驱动不了。后来在51中写了个类似的程序,却可以用。请教!
————————————————————— AVR程序 —————————————————————————
#include <iom16v.h>
#include <macros.h>
#define STR4094_Disable() PORTA&=~BIT(3)
#define STR4094_Enable() PORTA|=BIT(3)
#define D4094_Low() PORTA&=~BIT(4)
#define D4094_High() PORTA|=BIT(4)
#define CLK4094_Low() PORTA&=~BIT(5)
#define CLK4094_High() PORTA|=BIT(5)
#define uchar unsigned char
#define uint unsigned int
#pragma data:code
const table[]={0x3f,0x06,0x5b,0x4f, //0~3 //(1<<PA3)
0x66,0x6d,0x7d,0x07, //4~7
0x7f,0x6f,0x77,0x7c, //8~b
0x39,0x5e,0x79,0x71
};
void delay(uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<1141;j++);
}
}
void write4094(uchar Dat)
{
uchar i;
STR4094_Disable();
for(i=0;i<8;i++)
{
CLK4094_Low();
if(Dat & 0x01) D4094_High(); else D4094_Low();
delay(1);
CLK4094_High();
Dat>>=1;
}
STR4094_Enable();
}
void main()
{
DDRA=1;
PORTA=0xFF;//|=BIT(7);//数码管段选端。
write4094(0x01);
DDRB=1;
PORTB=0;
PORTB=0x55;//table[0];//最后4094并行的输出值。
}
————————————————————————————————————51——————————————————————————————
#include <reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit able=P1^2;
sbit clk=P1^3;
sbit shu=P1^4;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write4094(uchar Dat)
{
uchar i;
able=0;
for(i=0;i<8;i++)
{
clk=0;
if(Dat & 0x01) shu=1; else shu=0;
delay(1);
clk=1;
Dat>>=1;
}
able=1;
}
void main()
{
while(1)
{
write4094(0x55);
}
}
|