📄 cbus.c
字号:
//---------------------------------------------------------------------------------------------------
// Project:- DE8681
// Filename:- CBUS.C
// Description:- SPI interface to CMX868.
// Programmer:- D.T.F
// Version:- 2.0
// Created:- 28th February 2002
// Last modified:-
//---------------------------------------------------------------------------------------------------
// (C) Consumer Microcircuits Ltd 2002
//
// This firmware was designed by:-
// Consumer Microcircuits Ltd,
// Langford, Maldon,
// ESSEX
// CM9 6WG.
// in the UK for use with CML evaluation kits only and is based on UK originated technology.
// Please contact
// sales@cmlmicro.co.uk
// +44 (0)1621 875500
// for licensing details.
//---------------------------------------------------------------------------------------------------
#define CBUS_C
#include "ef8681.h"
void wr_cbus(unsigned char cbus_addr, unsigned char cbus_byte)
{
PICCSN = 0; // Clear CSN
load_spi(cbus_addr); // Load CBUS address byte
load_spi(cbus_byte); // Load CBUS byte
PICCSN = 1; // Set CSN
}
void wr16_cbus(unsigned char cbus_addr, unsigned int cbus_word)
{
PICCSN = 0; // Clear CSN
load_spi(cbus_addr); // Load CBUS address byte
load_spi((cbus_word >> 8) & 0xFF); // Load CBUS MS byte
load_spi(cbus_word & 0xFF); // Load CBUS LS byte
PICCSN = 1; // Set CSN
}
unsigned char rd_cbus(unsigned char cbus_addr)
{
unsigned char cbus_byte;
PICCSN = 0; // Clear CSN
load_spi(cbus_addr); // Load CBUS address byte
cbus_byte = load_spi(0x00); // Read CBUS byte
PICCSN = 1; // Set CSN
return (cbus_byte); // Return CBUS Byte
}
unsigned int rd16_cbus(unsigned char cbus_addr)
{
unsigned int cbus_word;
unsigned char cbus_lsbyte,cbus_msbyte;
PICCSN = 0; // Clear CSN
load_spi(cbus_addr); // Load CBUS address byte
cbus_msbyte = load_spi(0x00); // Read CBUS MS byte
cbus_lsbyte = load_spi(0x00); // Read CBUS MS byte
PICCSN = 1; // Set CSN
cbus_word = ((cbus_msbyte & 0xFF) << 8) | (cbus_lsbyte & 0xFF);
return (cbus_word); // Return CBUS Word
}
void reset_cbus()
{
PICCSN = 0; // Clear CSN
load_spi(CMXGENRESET); // Load general reset byte
PICCSN = 1; // Set CSN
// Clear CMX868 write shadow registers
CMXGENCTRL = 0;
CMXTXMODE = 0;
CMXRXMODE = 0;
CMXTXDATA = 0;
CMXTXDATAV14 = 0;
CMXPROG = 0;
CMXTESTADDR = 0;
CMXTESTWR = 0;
}
void pwrup()
{
XTAL = USER_XTAL; // Ensure correct CMX868 Xtal is selected (S24 Bit 0)
PWRUP = 1; // Power Up CMX868
RESET = 1; // Initially hold internal circuitry in reset condition
wr16_cbus(CMXGENCTRL_ADDR,CMXGENCTRL); // Update CBUS register
DelayMs(20); // 20ms Power Up Delay
RESET = 0; // Normal Operation
wr16_cbus(CMXGENCTRL_ADDR,CMXGENCTRL); // Update CBUS register
}
unsigned char load_spi(unsigned char loadvalue)
{
SSPBUF = loadvalue;
while(!SSPIF) // Wait until SSP interrupt flag is clear
continue;
SSPIF = 0; // Clear SSP interrupt flag
return(SSPBUF);
}
void init_spi()
{
SSPCON = 0; // SSPM3:SSPM0=0, SPI Master Mode, Clock=Fosc/4.
CKP = 0; // Idle state for clock is LO
STAT_CKE = 1; // With CKP = 0 and CKE = 1 data transmitted on rising edge
SSPEN = 1; // Enables serial port and configures SCK, SDO and SDI as serial port pins.
SSPIF = 0; // Clear SSP interrupt flag
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -