发表于:2007-10-24 20:31:00
楼主
我用PL3120/PL3150的MiniEVK学习neuron C,编写了一个小的显式报文的发送程序.按照书上写的,调用msg_send()后, 有msg_succeed事件发生, 但是却没有实际的信号上到电力线上, 请帮我看看有什么问题?
#include <isi.h>
#include <mem.h>
#include <stdlib.h>
#include <control.h>
#include <snvt_cfg.h>
#pragma num_alias_table_entries 4
#pragma num_addr_table_entries 5
#pragma enable_io_pullups
#pragma codegen optimization_on
#pragma codegen cp_family_space_optimization
#pragma set_node_sd_string "MGLight"
IO_4 input bitshift numbits(8) clockedge(-) ioButtons;
IO_6 output bit ioButtonLd = 1;
#define MG_BUTTONS_DEBOUNCE 3
unsigned GetButtons(void) {
unsigned Buttons, Index;
Buttons = 0xFFu;
for(Index = 0; Index < MG_BUTTONS_DEBOUNCE; ++Index) {
// capture parallel lines:
io_out(ioButtonLd, 0);
io_out(ioButtonLd, 1);
// take a sample and debounce:
Buttons &= (unsigned)io_in(ioButtons);
}
return ~Buttons;
}
IO_2 output bitshift numbits(8) ioLEDs;
IO_1 output bit ioLEDLd = 1;
unsigned PreviousLEDs = 0;
void SetLEDs(unsigned LEDs, unsigned Mask) {
// We may only want to set some LEDs, indicated by Mask. Bits outside the
// mask are added from the previous pattern:
LEDs |= PreviousLEDs & ~Mask;
PreviousLEDs = LEDs;
// LEDs are driven active low - the SetLEDs function handles the inversion
// so that the application developer may think in positive logic:
io_out(ioLEDs, ~LEDs);
// strobe:
io_out(ioLEDLd, 0);
io_out(ioLEDLd, 1);
}
when(reset)
{
SetLEDs(0x00, 0xFFu); // LEDs into defined state
}
mtimer repeating kbTick = 50ul;
unsigned Previous = 0;
unsigned LED = 0;
msg_tag bind_info(nonbind) tag_out;
when(timer_expires(kbTick))
{
unsigned Buttons;
Buttons = GetButtons();
if(Previous!=Buttons)
{
Previous = Buttons;
LED = LED^Buttons;
SetLEDs(LED,0xFF);
msg_out.tag = tag_out;
msg_out.code = LED;
msg_send();
}
/*else
{
SetLEDs(LE