我正在学习PIC (pic18f4550)和非常新的微控制器编程。我正在尝试获取PORTA上三个按钮的值,并通过74LS595将其作为X坐标发送到一个8x8领导矩阵。问题是,当我按下按钮来创建不同的值时,led矩阵的值不会改变。我在模拟变形,所以我想我不需要借记符功能。这是我的代码和原理图:
#include<p18f4550.h>
#define SCK LATBbits.LATB0
#define DATA PORTBbits.RB1
#define SCL PORTBbits.RB2
void Data_in(unsigned char k){
DATA=k;
SCK=0;
SCK=1;
}
void LatchData(){
SCL=0;
SCL=1;
}
void Send1byte(unsigned char data)
{
unsigned char i,temp;
for(i=0;i<8;i++)
{
temp = data & (1<<i);
if(temp)
{
DATA = 1;
}
else
{
DATA = 0;
}
SCK = 0;
SCK = 1;
}
SCL = 0;
SCL = 1;
}
unsigned char getMatrixX(unsigned char in_X)
{
switch(in_X)
{
case 0: // the value stuck here
return 0b01111111;
case 1:
return 0b10111111;
case 2:
return 0b11011111;
case 3:
return 0b11101111;
case 4:
return 0b11110111;
case 5:
return 0b11111011;
case 6:
return 0b11111101;
case 7:
return 0b11111110;
default:
return 0b11111111;
}
}
void main()
{
TRISA = 1;
TRISC = 1;
TRISB = 0;
TRISD = 0;
PORTD = 0x80;
while(1){
Send1byte(getMatrixX(LATA));
}
}这是指向我的原理图:我的原理图的链接
非常感谢任何解决方案和建议。对不起我的英语不好。
发布于 2014-05-23 19:59:21
RA0:RA3的模拟函数是这里真正的问题,因此添加这些函数将修复以下问题:
ADCON1 = 0x0F; // All digital inputs
CMCON = 0x07; // Comparators off (note this is the POR default)谢谢大卫在这个问题:https://electronics.stackexchange.com/questions/111614/pic-programming-get-value-of-multiple-buttons-to-a-port/111625?noredirect=1#111625,他解释得很好。
https://stackoverflow.com/questions/23835405
复制相似问题