|
楼主 |
发表于 2009-9-16 17:48:34
|
显示全部楼层
摸索了一天,还是没什么进展。
矩阵我没有定时扫描,用行列扫描。
矩阵为PD2-PD6输出(行),PC0-PC3输入(列)
希望大家看看问题出在什么地方,感谢!
/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.4 Standard
Automatic Program Generator
?Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 2009-09-14
Author :
Company :
Comments:
Chip type : ATmega48
Clock frequency : 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 128
*****************************************************/
#include <mega48.h>
#include <delay.h>
#include <sleep.h>
// Pin change 8-14 interrupt service routine
interrupt [PCINT1] void pin_change_isr1(void)
{
sleep_disable();
}
void main(void)
{
unsigned char Key=0;
// Crystal Oscillator division factor: 8
#pragma optsize-
CLKPR=0x80;
CLKPR=0x03;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
PORTB=0x08;
DDRB=0x08;
PORTC=0xFF;
DDRC=0x00;
PORTD=0x01;
DDRD=0xFF;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// Interrupt on any change on pins PCINT0-7: Off
// Interrupt on any change on pins PCINT8-14: On
// Interrupt on any change on pins PCINT16-23: Off
EICRA=0x00;
EIMSK=0x00;
PCICR=0x02;
PCMSK1=0x0F;
PCIFR=0x02;
// Global enable interrupts
#asm("sei")
while (1)
{
Key=GetKeyboard();
switch(Key)
{
case KB_P1:
js=0;
PORTD&=~(1<<LED_PIN);
SendData(KB_P1);
break;
default:
PORTD|=1<<LED_PIN;
if(++js>=20000)
{
js=0;
PORTD&=~(1<<0); //亮
delay_ms(1000);
PORTD|=1<<0; //灭
sleep_enable(); //允许进入低功耗模式
powerdown(); //进入掉电模式。
}
}
};
} |
|