1755 views|0 replies

3836

Posts

19

Resources
The OP
 

msp430f149+peripheral tlv61612-bit DA conversion module [Copy link]

The following is made by replacing the 12-bit DC chip 5616. It took 2 hours to adjust it. It's unbearable. The code is as follows (or explain it first: P2.0 port - DIN P2.1 port - SCLK P2.2 port - CS/ P2.3 port - FS) It is more reliable to write the clock by yourself. The key external interrupt is used to change the digital value written into 5616. The key +-50 #include
#define uchar unsigned char #define uint unsigned int #define DA5616_clk_H P2OUT|=BIT1//P2.1 #define DA5616_clk_L P2OUT&=~BIT1//P2.1 #define DA5616_cs_H P2OUT|=BIT2//P2.2 #define DA5616_cs_L P2OUT& =~BIT2//P2.2 #define DA5616_fs_H P2OUT|=BIT3//P2.3 #define DA5616_fs_L P2OUT&=~BIT3//P2.3 uint data; void int_clock() { uchar i; BCSCTL1&=~XT2OFF; // External high-speed clock crystal oscillator BCSCTL2|=SELM1 + SELS; //MCLK,SMLCK both use external high-speed clockdo { IFG1&=~OFIFG; for(i=0;i<100;i++) _NOP(); }while((IFG1&OFIFG)); IFG1 &=~OFIFG; } void io_init () { P2DIR=BIT3+BIT1+BIT2+BIT0; //P2.0 P2.1 P2.2 P2.3 set output} /**** DA conversion****/ void DA5616(uint da) { uchar i; DA5616_cs_L; DA5616_fs_L; DA5616_clk_L; for(i=0;i<16;i++) { P2OUT |=(da&0x8000)>>15; DA5616_clk_H; da<<=1; //da binary data shift left one bit * 2 DA5616_clk_L; } P2OUT&=0xfe; DA5616_fs_H; DA5616_cs_H; } void DA5616_out(float data1) { uint temp; temp = data1*2048/2.5; DA5616(temp); } void main( ) { // Stop watchdog timer to prevent time out reset // Close all IO ports P1DIR = 0XFF; P1OUT = 0XFF; P2DIR = 0XFF; P2OUT = 0XFF; P3DIR = 0XFF; P3OUT = 0XFF; P4DIR = 0XFF; P4OUT = 0XFF ; P5DIR = 0XFF; P5OUT = 0XFF; P6DIR = 0XFF; P6OUT = 0XFF; P1IES = 0x30; // Select falling edge interrupt for P1.0~P1.3 P1IE = 0x30; // Enable interrupt P1DIR = BIT1; // Set P1.0~P.3 to input state and P.7 to output P1OUT = 0; WDTCTL = WDTPW + WDTHOLD; //dog timer data = 1400; int_clock(); io_init(); DA5616(data); _EINT(); while(1) { } } /********* ********************************** Function name: Port1_ISR Function: interrupt service function of port P1 Parameter: no return Value: None********************************************/ #pragma vector = PORT1_VECTOR __interrupt void Port1_ISR (void) { _DINT (); if (P1IFG & BIT4) { P1IFG = 0x00; // clear interrupt flag data -= 20; //DAC output reduces 100 offsets int_clock(); io_init(); DA5616(data); } else if(P1IFG & BIT5) { P1IFG = 0x00; //clear interrupt flag data += 20 ; //DAC output increases by 100 offset int_clock(); io_init(); DA5616(data); } else _NOP(); P1IFG = 0x00; //clear interrupt flag _EINT(); }ok ~


This post is from Microcontroller MCU
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list