本帖最后由 snowmaple 于 2012-5-6 12:39 编辑
我用C8051F120单片读取74LS165的数据,但是E—H 4位读取的数据不对:
E:应为00010000,读出来:00010001;
F:应为00100000,读出来:00100100;
G:应为01000000,读出来:01010101;
H:应为10000000,读出来:11111111;
如果用普通51单片机读数没有发生错误,请C8051F120单片机高手为我解惑,万分感谢!!!
附:下面为源程序代码,其中data165为读取的数据:
#include <c8051f120.h>
#include <intrins.h>
#include <absacc.h>
#include <stdlib.h> //标准函数
#include <stdio.h> //I/O口函数
#define SYSCLK 22118400
sbit HC165_CLK=P4^4;
sbit HC165_READ=P4^5;
sbit HC165_PL=P4^3;
void SYSCLK_Init (void);
void PORT_Init();
void timer0_int();
unsigned char Read_LED(void);
void main()
{
unsigned char data165;
WDTCN = 0xde; // 关闭WDT
WDTCN = 0xad;
SYSCLK_Init ();
PORT_Init();
SFRPAGE=CONFIG_PAGE;
while(1)
{
data165=Read_LED();
}
}
//-----------------------------------------------------------------------------
// 系统时钟配置
//-----------------------------------------------------------------------------
void SYSCLK_Init (void)
{
int i = 0;
//char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page
SFRPAGE = CONFIG_PAGE; // set SFR page
OSCXCN = 0x67; // start external oscillator with
// 22.1184MHz crystal
for (i=0; i < 3000; i++) ; // XTLVLD blanking interval (>1ms)
while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
CLKSEL = 0x01; //SYSCLK derived from the External Oscillator circuit
OSCICN &= ~0x80; //Internal Oscillator Disabled
}
//-----------------------------------------------------------------------------
// I/O配置
//-----------------------------------------------------------------------------
void PORT_Init()
{
char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page
SFRPAGE = CONFIG_PAGE;
XBR2 = 0x40;
XBR0 = 0x04; //允许UART0,RX,TX连到2个端口引脚. XBR0=0000,0100
XBR1 = 0x00;
// 允许交叉开关和弱上拉
P3MDOUT=0xFF;
P4MDOUT=0xFF;
P0MDOUT |= 0x01;
SFRPAGE = SFRPAGE_SAVE; // Restore SFR page
}
unsigned char Read_LED(void)
{
unsigned char i,dat=0;
SFRPAGE=CONFIG_PAGE;
HC165_PL=0;
HC165_PL=1;
for(i=0;i<8;i++)
{
HC165_CLK=0;
dat = dat<<1;
if(HC165_READ)
dat|=0x01;
HC165_CLK=1;
}
return dat;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>