|
如题,以下是我的部分代码:
#include <iom8v.h>
#include <macros.h>
#include <stdio.h>
void port_init(void)
{
PORTB = 0x10;
DDRB = 0x2C;
PORTC = 0x21; //m103 output only
DDRC = 0x26;
PORTD = 0x22;
DDRD = 0x09;
}
void spi_init(void)
{
SPCR = 0xD0; //setup SPI
SPSR = 0x00; //setup SPI
}
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
spi_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00;
SEI();
}
void sends(unsigned char x){
WDR();
while(k != 0);
k = x;
DDRB |= 0x08;//DDRB.2=1;
PORTB &= ~0x08;//PORTB.2 = 0;
tt = 1;
SPDR = 0xAF;
SPCR |= 0x80;//SPIE = 1;
}
#pragma interrupt_handler spi_stc_isr:11
void spi_stc_isr(void)
{
if(tt < k){
SPDR = ttt[tt];
tt++;
PORTC ^= 0x20;
}
else{
k = 0;
DDRB &= ~0x08;//DDRB.2=0;
PORTB |= 0x08;//PORTB.2 = 1;
}
}
void main(void)
{
CLI();
init_devices();
SEI();
ttt[1] = 0x66;
ttt[2] = 0x77;
ttt[3] = 0x88;
sends(4);
ttt[1] = 0x44;
ttt[2] = 0x55;
ttt[3] = 0x66;
sends(4);
}
我用了M8从机作接收,接收到的用串口发出来,在PC机上就串口助手接收,结果是收到 A5 44 55 66,仿真的时候显示,执行到第一次sends(4)的时候发完A5之后就没有进入中断,跳出来执行ttt[1]=0x44;了继而执行第二次sends(4),请问马老师这是什么原因?
-----此内容被noname于2005-06-20,11:24:03编辑过
-----此内容被noname于2005-06-20,14:51:03编辑过
-----此内容被noname于2005-06-24,08:37:20编辑过 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|