?? mc68hc908rf2.txt
字號:
DCLK = 0;
}
/*********************************************************/
/* 函數(shù):void Transmit_Prepare(void) */
/* 功能: */
/*********************************************************/
void Transmit_Prepare(void){
uchar i;
uchar fast_mode_flag = 0;
Check_battery();
if(5==(Max_Pres-Min_Pres)) {
Fast_Data_Mode();
}
else{
Normal_Data_Mode();
}
i = Tx_count;
for(i;i>0;i--){
Daytona_Tx_Read(); // Read temperature and pressure data.
Transmit_Frame();
Random_delay(); // Add a random delay (~0 - 100 ms).
}
}
/**************************************************************/
/* Transmit_Frame */
/* Description : Make the data frame and transmit it out. */
/* In : */
/* Out : */
/* local variables : */
/**************************************************************/
void Transmit_Frame(void){
make_frame();
tango_Enable = 1;
tempo(wait_1_8ms); // wake up Romeo2 (mc33594)
tempo(wait_1_8ms); // wake up Romeo2 (mc33594)
/* Description : it transmits a tone at 9600 bauds for the programmed time */
asm lda TSC0
TSC0 &= 0xE3; // initial output = H
// #%11100011
// \\\_______;Pin under port control,
// \________;Initial output = High
// MS0B|MS0A|ELS0B|ELS0A = X000 means initial output==high level.
// initialize timer0
Current_Tx_Bit = 1;
Next_Tx_Bit = 1;
asm lda TSC
TSC = 0x37;
asm lda TSC0
TSC0 =0x54;
// TSC = 0x30;
TMOD = UHF_Period; //for 9600 Baud
TCH0 = UHF_Duty_Cycle;
TSC_TSTOP = 0; // start the timer.bit5
Transmit_Message(); // transmit the UHF frame
}
/**************************************************************/
/* PROJECT : RF key demonstrator (ASK or FSK) */
/* Functions: */
/* Make_frame */
/* Read_ID */
/* Make_daytona_data */
/* Calculate_checksum */
/**************************************************************/
void make_frame(void){
uchar i,check_sum = 0;
Tx_Byte[0] = 0xFB; // Preamble+ID+Header
Tx_Byte[1] = 0x86;
Tx_Byte[2] = ID[0];
Tx_Byte[3] = ID[1];
Tx_Byte[4] = ID[2];
Tx_Byte[5] = ID[3];
// Tx_Byte[6] = PRESSURE;
// Tx_Byte[7] = TEMPERATURE;
// Tx_Byte[8] = STATUS;
// for no sensor transmit test. status byte is incerment by 1 each time.
// Tx_Byte[2] = 0x01; //ID[0]
// Tx_Byte[3] = 0x23; //ID[1]
// Tx_Byte[4] = 0x45; //ID[2]
// Tx_Byte[5] = 0x67; //ID[3]
Tx_Byte[6] = 0x44; //PRESSURE
Tx_Byte[7] = 0x55; //TEMPERATURE
Tx_Byte[8] = 0x66; //STATUS
// calculate from ID[0] to STATUS.
for(i=0;i<7;i++){
check_sum += Tx_Byte[i+2];
}
Tx_Byte[9] = ~check_sum;//CHECKSUM
}
/*****************************************************************************/
/* Transmit */
/* Description : it transmits data at 9600 bauds in Manchester */
/* In : Tx_byte */
/* Out : */
/* local variables : H:X, current_tx_bit,next_tx_bit,current_tx_byte */
/*****************************************************************************/
void Transmit_Message(void){
uchar i,j;// i==byte_counter,j==bit_counter;
uchar mask=0x80;
//include FB86+ID[0]~ID[3]+PRESSURE+TEMPERATURE+STATUS+CHECKSUM
for(i=0;i<10;i++){
current_tx_byte = Tx_Byte[i];
for(j=8;j>0;j--){
Current_Tx_Bit = Next_Tx_Bit;
if(current_tx_byte&mask) { //here error before :2006.01.05
Next_Tx_Bit = 1;
}
else {
Next_Tx_Bit = 0;
}
current_tx_byte <<=1;
asm wait
}
}
asm LDA TSC
TSC_TOF = 0;
while(!TSC_TOF);
tango_DATA_RF = 0;
TSC0 = 0;
tango_DATA_RF = 0;
tempo(UHF_Period);
tempo(UHF_Period);
tempo(UHF_Period);
tango_Band = 1; // shut down the RF, keep at 315/434MHz
asm LDA TSC
TSC = 0x30;
}
void Normal_Data_Mode(void){
Tx_count = 1;
}
void Fast_Data_Mode(void){
Tx_count = 1;
}
void Random_delay(){
asm LDA TCNTL
Random_Number = TCNTL &0x07;
if(Random_Number){
switch(Random_Number){
case 2:{
tempo(49151); //25ms
}break;
case 4:{
tempo(65535); //50ms
tempo(32767);
}break;
case 5:{
tempo(65535); //75ms
tempo(65535);
tempo(16383);
}break;
default:{
tempo(65535); //100ms
tempo(65535);
tempo(65535);
}
}
}
}
// This is a constant delay for approximately 0.8 seconds, used while in
// fast transmission mode.
void delay_200_ms(void){
uchar i;
uint ch;
for(i=6;i>0;i--){
ch = 0xFFFF;
tempo(ch);
}
}
void delay_800_ms(void){
uchar i;
uint ch;
for(i=24;i>0;i--){
ch = 0xFFFF;
tempo(ch);
}
}
/*****************************************************************************/
/* tempo */
/* Description : it waits for n cpu cycles */
/* In : H:X */
/* Out : TMOD, TSC */
/* local variables : */
/*****************************************************************************/
void tempo(uint ch){
asm LDA TSC
TSC_TOF = 0;
TSC |= 0x30; // stop the counter,
TMOD = ch;
TSC_TSTOP = 0; // start the timer
while(!TSC_TOF);
}
/**************************************************************/
/* Init */
/* Description : it initializes the MCU */
/* In : */
/* Out : TEMPERATURE, PRESSURE */
/* local variables : */
/**************************************************************/
void init_sys(void){
init_ports();
init_icg();
init_timer();
Tx_count = 0;
Max_Pres = 0;
Min_Pres = 0xFF;
TEMPERATURE = 0x80;
PRESSURE =0x80; // These initialize the values to 1/2 FS
// for the moving average. This way, the readings will
// probably converge to the mean quicker than with whatever
// random value these variables start at.
init_kbi();
}
/**************************************************************/
/* Init_KBI */
/* Description : it enables keyboard interrupts */
/* In : */
/* Out : INTKBSR, INTKBIER */
/* local variables : */
/**************************************************************/
void init_kbi(void){
asm bset 1,INTKBSCR // mask keyboard interrupt
asm bset 5,INTKBSCR // & IRQ
asm bset 6,INTKBSCR // clear any pending IRQ request
asm bset 2,INTKBSCR // clear any pending keyboard request
asm bclr 0,INTKBSCR // keyboard interrupt triggered by falling edge only
asm bset 3,INTKBIER // enable keyboard interrupt KBD3 to wakeup from stop
// by Daytona
asm bclr 1,INTKBSCR // enable keyboard interrupts
}
/*****************************************************************************/
/* Init_ICG */
/* Description : it initializes the ICG @ 2 MHz */
/* In : */
/* Out : ICGCR, ICGMR */
/* local variables : */
/*****************************************************************************/
void init_icg(void){
ICGCR = 0x08; // mcu clk = internal clock
ICGMR = 0x1A; // mcu clk = 2.000 MHz
while(!ICGCR_ICGS); // wait for PLL stable
}
/*****************************************************************************/
/* Init_Timer */
/* Description : it initializes the timer to use the internal clock. The */
/* timer is re-configured for transmission then returns to this default. */
/* In : */
/* Out : TSC */
/* local variables : */
/*****************************************************************************/
void init_timer(void){
asm lda TSC
TSC = 0x30; //Clear & stop the timer, disable interrupts
}
/*****************************************************************************/
/* Init_ports */
/* Description : it initializes MCU ports */
/* In : */
/* Out : DDRA, DDRB */
/* local variables : */
/*****************************************************************************/
void init_ports(void){
// Initialize Tango3 control (not quite enough pins on PORTB, Mode uses PORTA)
DDRB = 0x07; // DDRB=#%00000111
// PTB0 - MODE OUTPUT
// PTB1 - ENABLE OUTPUT
// PTB2 - DATA OUTPUT
// PTB3 - DATACLK INPUT
// PTA7 - BAND OUTPUT (Initialized below)
// Initialize Daytona Control (and one pin for Tango3 control)
DDRA = 0xF6; // DDRA=#%11111100
// PTA0 - RUN STATE INPUT (prevent floating input)
// PTA1 - DOUTb INPUT
// PTA2 - S1/Vpp OUTPUT
// PTA3 - S0 OUTPUT
// PTA4 - DCLK OUTPUT
// PTA5 - DDATA OUTPUT
// PTA6 - N/C OUTPUT (prevent floating input)
// PTA7 - MODE OUTPUT (to Tango3, see above)
PTA = 0;
PTB = 0;
tango_Mode = 1; // [PTA7]Set Tango into FSK mode
tango_Band = 1; // [PTB0]Set Tango for 434/315 MHz transmission
}
//*** Place Daytona in Read Temperature Mode
void tango_read_temperature_mode(void){
S1 = 1;
S0 = 0;
}
//*** Place Daytona in Read Pressure Mode
void tango_read_pressure_mode(void){
S1 = 0;
S0 = 1;
}
//*** Place Daytona in SAMPLE Mode
void tango_read_data_out(void){
S1 = 1;
S0 = 1;
}
//*** Place Daytona in IDLE Mode
void tango_idle(void){
S1 = 0;
S0 = 0;
}
//*** Place MCU in asleep_tx Mode
void asleep_tx(void){
init_sys(); // Re-initialize all variables and KBD interrupts, and
tango_idle(); // wait for wake-up.
asm stop
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -