dwz518 发表于 2007-5-24 14:57:36

马老师,求助8279!

马老师,已经调俩星期,都没结果!

我用8515做8279的扩展键盘实验,用频率发生器的PB0口做8279的时钟,cs和pc2,a0和pc0,rd,wr 数据线依次连好,用SL0,SL1和RL0,RL1接四个按键,IRQ通过反相器接INT0,意思是想通过按键动作控制PB1,PB2的外接发光二极管。8279没有外接数码管!

先是用AD数据总线,后来用一般IO口程序



程序如下:

//ICC-AVR application builder : 2007-5-22 9:20:00

// Target : M8515

// Crystal: 7.3728Mhz



#include <iom8515v.h>

#include <macros.h>

#define Ctr8279   (*(volatile char *)0x7100)

#define D8279   (*(volatile char *)0x7000)

#define unchar unsigned char

#define unint unsigned int



unchar int0_flag;

void port_init(void)

{



PORTB = 0x00;

DDRB= 0x07;



PORTD = 0x00;

DDRD= 0x00;

PORTE = 0x00;

DDRE= 0x00;

}



//TIMER0 initialize - prescale:1

// WGM: Normal

// desired value: 1MHz

// actual value:1.053MHz (5.1%)

void timer0_init(void)

{

TCCR0 = 0x00; //stop timer

TCNT0 = 0xF9; //set count value

OCR0= 0xFE;

TCCR0 = 0x11; //start timer

}



#pragma interrupt_handler timer0_comp_isr:15

void timer0_comp_isr(void)

{

//compare

OCR0= 0xFE;

PORTB^=0X02;

}



#pragma interrupt_handler timer0_ovf_isr:8

void timer0_ovf_isr(void)

{

TCNT0 = 0xF9; //reload counter value

OCR0= 0xFE;

//PORTB^=0X01;

}



#pragma interrupt_handler int0_isr:2

void int0_isr(void)

{

//external interupt on INT0

int0_flag=1;

}



//call this routine to initialize all peripherals

void delay(void)

{

unint i;

for( i=0;i<125;i++);

}



void init_devices(void)

{

//stop errant interrupts until set up

CLI(); //disable al l interrupts

port_init();

timer0_init();

MCUCR = 0xC2;   //引脚第二功能选择,等待状态选择 中断配置

EMCUCR = 0x04;    //无等待状态

GICR = 0x40;      //外部中断使能

TIMSK = 0x03;

SEI(); //re-enable interrupts

//all peripherals are now initialized

}

//void clear(void)

//{

//unchar i;

//      Ctr8279=0xd1;

   //   i=Ctr8279;i&=0x80;

   //   while(i==0x80){i=Ctr8279;i&=0x80;}

//}

void init8279(void)

{

Ctr8279=0x21;            //时钟配置



delay();

Ctr8279=0x01;            //键盘扫描方式000 00001

delay();

}

unchar keyvalue(void)

{

Ctr8279=0x40;            //读显示



delay();



return(D8279);

delay();

}



void main(void)

{

unchar keydata;

init_devices();

init8279();

delay();   

do{

//Ctr8279=0xFF;

if(int0_flag)

{

   

   

   PORTB^=0x02;

   keydata=keyvalue();

   //PORTB=keydata;

   int0_flag=0;

   

   /*switch(keydata)

   {

   case (0x01):

   PORTB=0x01;

   break;                                                                                                                                                                                                                                                                  

   case(0x02):

   PORTB=0x02;

   break;

   case (0x04):

   PORTB=0x04;

   break;

   case (0x08):

   PORTB=0x00;

   break;

   }*/

   

}

else

PORTB^=0X04;

}while(1);

}



一般IO口





//ICC-AVR application builder : 2007-5-22 11:25:09

// Target : M8515

// Crystal: 7.3728Mhz



#include <iom8515v.h>

#include <macros.h>

#define uchar unsigned char

#define uint unsigned int

#define write0 PORTD&=~BIT(PD6)

#define write1 PORTD|=BIT(PD6)

#define read0 PORTD&=~BIT(PD7)

#define read1 PORTD|=BIT(PD7)

#define cs0 PORTC&=~BIT(PC2)

#define cs1 PORTC|=BIT(PC2)

#define Anumber PORTC&=~BIT(PC0)

#define Actr PORTC|=BIT(PC0)



uchar data;

uint i;

uchar int0_flag=0;

void port_init(void)

{



PORTB = 0x04;

DDRB= 0x07;

PORTC = 0x00;

DDRC= 0xFF;

PORTD = 0x00;

DDRD= 0xFF;



}



//TIMER0 initialize - prescale:1

// WGM: Normal

// desired value: 1MHz

// actual value:1.053MHz (5.1%)

void timer0_init(void)

{

TCCR0 = 0x00; //stop timer

TCNT0 = 0xF9; //set count value

OCR0= 0x07;

TCCR0 = 0x01; //start timer

}



#pragma interrupt_handler timer0_comp_isr:15

void timer0_comp_isr(void)

{

//compare

//OCR0= 0x07;

}



#pragma interrupt_handler timer0_ovf_isr:8

void timer0_ovf_isr(void)

{

TCNT0 = 0xF9; //reload counter value

PORTB^=0X01;

//PORTB^=0x02;

}



#pragma interrupt_handler int0_isr:2

void int0_isr(void)

{

//external interupt on INT0

int0_flag=1;

}



//call this routine to initialize all peripherals

void init_devices(void)

{

//stop errant interrupts until set up

CLI(); //disable all interrupts

port_init();

timer0_init();



MCUCR = 0x02;

EMCUCR = 0x00;

GICR = 0x40;

TIMSK = 0x03;

SEI(); //re-enable interrupts

//all peripherals are now initialized

}



void init8279(void)

{

cs0;

Actr;               //片选及A控制

DDRA=0xff;          //A口输出

write0;             //写信号有效

//NOP();

PORTA=0x22;         //时钟配置

NOP();

write1;             //写信号置高

NOP();

write0;             //写信号有效

//NOP();

PORTA=0x01;         //键盘模式,译码

NOP();

write1;             //写信号置高

NOP();

cs1;                //片选无效

}

uchar read(void)

{

cs0;      

Actr;            //片选及A控制

DDRA=0xff;         //A口输出

write0;            //写信号

//NOP();

PORTA=0x40;       //读取命令

//NOP();

write1;         //写信号置高

NOP();

Anumber;          //片选及A控制

PORTA=0XFF;       //上拉使能

DDRA=0x00;      //A口输入

//NOP();

read0;            //读信号

NOP();

return(PINA);      

NOP();

read1;            //读写置高

NOP();

cs1;

}

void delay(void)

{

unsigned int i;

for (i=0;i<150;i++);

}



void delay_nms(unsigned n)

{

unsigned int i;

for (i=0;i<n;i++)

       delay();

}



void main()

{

init_devices();

delay_nms(500);

init8279();

do

{

if(int0_flag)

   {PORTB^=0x02;

   data=read();

   int0_flag=0;}

else

   {PORTB^=0X02;}

}while(1);

}

dwz518 发表于 2007-5-25 09:44:36

各位,谁熟悉8279啊?
页: [1]
查看完整版本: 马老师,求助8279!