#include
unsigned char DuanMa[10]={0xc0,0xf9,0xa4,0xb0, 0x99,0x92,0x82,0xf8,0x80,0x90};// 显示段码值0~9
unsigned char WeiMa[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//分别对应相应的数码管点亮,即位码
unsigned char TempData[8]; //存储显示值的全局变量
#define AddWr 0x90 //写数据地址
#define SDA BIT6
#define SCL BIT7
void sda_high(void)
{
//将sda设置为输出模式
P1DIR |=SDA;
//sda管教输出为高电平
P1OUT |=SDA;
return;
}
void sda_low(void)
{
//将SDA设置为输出模式
P1DIR |=SDA;
//sda管教输出为低电平
P1OUT &= ~(SDA);
return;
}
void scl_high(void)
{
//将SCL设置为输出模式
P1DIR |= SCL;
//SCL管脚输出为高电平
P1OUT |= SCL;
return;
}
void scl_low(void)
{
//将scl设置为输出模式
P1DIR |=SCL;
//scl管教输出为低电平
P1OUT &= ~(SCL);
return;
}
void Start_I2c()
{
sda_high();
_NOP();
scl_high();
_NOP(); //起始条件建立时间大于4.7us,延时
_NOP();
_NOP();
_NOP();
_NOP();
sda_low();
_NOP(); //起始条件建立时间大于4.7us,延时
_NOP();
_NOP();
_NOP();
_NOP();
scl_low();
_NOP();
_NOP();
}
void Stop_I2c()
{
sda_low();
_NOP();
scl_high();
_NOP(); //起始条件建立时间大于4.7us,延时
_NOP();
_NOP();
_NOP();
_NOP();
sda_high();
_NOP(); //起始条件建立时间大于4.7us,延时
_NOP();
_NOP();
_NOP();
}
void SendByte(unsigned char c)
{
unsigned char BitCnt;
for(BitCnt=0;BitCnt
我解释一下我现在碰到的情况哈,主要是1.4,1.5完全没有输出,也就是没有波形,所以理所当然没办法使8591输出电压。但是我之后看官方例程,用的是USCI自带的IIc功能,烧到单片机里后发现好一点了,有时钟SCL输出了,但是SDA仍然没有,这就很苦恼,完全想不通为什么啊orz
以下是改过之后的官方例程,我只是改了从机地址(0x90)和控制位地址(0x40),别的都没改过
//******************************************************************************
// MSP430G2xx3 Demo - USCI_B0 I2C Master Interface to DAC8571, Write
//
// Description: Using UCB0TXIE, a continuous sine wave is output to the
// external DAC using a 16-point look-up table. Only one start condition
// is executed. Data is handled by the ISR and the CPU is normally in LPM0.
// ACLK = n/a, MCLK = SMCLK = BRCLK = default DCO = ~1.2MHz
//
// MSP430G2xx3 DAC8571
// ------------------ ------------
// -|XIN P1.7/UCB0SDA||SDA |
// | P1.6/UCB0SCL|---------------->|SCL I2C |
// -|XOUT | | SLAVE |
// | I2C MASTER | GND|A0 |
//
//
// DAC8571 I2C address = 0x4C (A0 = GND)
//
// D. Dang
// Texas Instruments Inc.
// February 2011
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************
#include "msp430g2553.h"
const unsigned char Sine_Tab[] = // 16 Point 16-bit Sine Table
{
0xFF, // MSB Word 0
0xFF, // LSB
0xF6, // MSB Word 1
0x40, // LSB
0xDA, // MSB Word 2
0x81, // LSB
0xB0, // MSB Word 3
0xFA, // LSB
0x7F, // MSB Word 4
0xFF, // LSB
0x4F, // MSB Word 5
0x03, // LSB
0x25, // MSB Word 6
0x7C, // LSB
0x09, // MSB Word 7
0xBD, // LSB
0x00, // MSB Word 8
0x00, // LSB
0x09, // MSB Word 9
0xBD, // LSB
0x25, // MSB Word 10
0x7C, // LSB
0x4F, // MSB Word 11
0x03, // LSB
0x7F, // MSB Word 12
0xFE, // LSB
0xB0, // MSB Word 13
0xFA, // LSB
0xDA, // MSB Word 14
0x81, // LSB
0xF6, // MSB Word 15
0x40 // LSB
};
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop Watchdog Timer
P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0,1.6SCL
P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0,1.7SDA
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = 0x90; // Set slave address
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
IE2 |= UCB0TXIE; // Enable TX ready interrupt
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
UCB0TXBUF = 0x40; // Write DAC control byte
__bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts
}
// USCI_B0 Data ISR
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
static unsigned char ByteCtr=0;
UCB0TXBUF = 0XFF ; // Transmit data byte
ByteCtr &= 0x1f; // Do not exceed table
}
求问各位大大