1550 views|0 replies

3836

Posts

19

Resources
The OP
 

How to realize 12864 display of 430f149 MCU AD sampling waveform [Copy link]

Use msp430g2553+AD voltage acquisition+12864 power display
Tip: The power meter made by msp430g2553+AD10 voltage acquisition+12864 power display obviously includes 12864 driver and AD acquisition
//************************************************************************
//ADC12 sequence channel and D12864 LCD module display program
//************************************************************************
#include <msp430x14x.h>
#define CPU_F ((double)8000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
/*12864 application instructions*/
#define CLEAR_SCREEN 0x01 //Clear screen instruction: clear the screen and AC value is 00H
#define AC_INIT 0x02 //Set AC to 00H. And the cursor moves to the origin position
#define CURSE_ADD 0x06 //Set the cursor movement direction and the overall rightward movement of the image.
#define FUN_MODE 0x30 //Working mode: 8-bit basic instruction set
#define DISPLAY_ON 0x0c //Display on, display cursor, and the cursor position is highlighted
#define DISPLAY_OFF 0x08 //Display off
#define CURSE_DIR 0x14 //Cursor moves to the right: AC=AC+1
#define SET_CG_AC 0x40 //Set AC, the range is: 00H~3FH
#define SET_DD_AC 0x80
#define P50 0
#define P51 1
#define P55 5
#define P56 6
#define P57 7
#define RS_CLR P5OUT &= ~(1 << P55) //RS set low
#define RS_SET P5OUT |= (1 << P55) //RS set high
#define RW_CLR P5OUT &= ~(1 << P56) //RW set low#
define RW_SET P5OUT |= (1 << P56) //RW set high
#define EN_CLR P5OUT &= ~(1 << P57) //E set low
#define EN_SET P5OUT |= (1 << P57) //E set high
#define PSB_CLR P5OUT &= ~(1 << P50) //PSB set low, serial port mode
#define PSB_SET P5OUT |= (1 << P50) //PSB set high, parallel port mode
#define RST_CLR P5OUT &= ~(1 << P51) //RST set low
#define RST_SET P5OUT |= (1 << P51) //RST set high
#define DataPort P4OUT //P4 port is data
portuint Results[32]; //Store the result of ADC
uchar shuzi[] = {"0123456789.V"};
uchar ptr[6];
uint Average;
uint Temp;
ulong caltmp[4];
//****************************************************************************
// System clock initialization
//****************************************************************************
void Clock_Init()
{
uchar i;
BCSCTL1&=~XT2OFF; //Turn on XT oscillator
BCSCTL2|=SELM1+SELS; //MCLK is 8MHZ, SMCLK is 8MHZ
do{
IFG1&=~OFIFG; //Clear oscillation flag
for(i=0;i<100;i++)
_NOP(); //Delay waiting
}
while((IFG1&OFIFG)!=0); //If the flag is 1, continue to loop and wait for
IFG1&=~OFIFG;
}
//****************************************************************************
// MSP430 internal watchdog initialization
//****************************************************************************
void WDT_Init()
{
WDTCTL = WDTPW + WDTHOLD; //Turn off the watchdog
}
//****************************************************************************
// Initialize IO port subroutine
//****************************************************************************
void Port_init()
{
P4SEL = 0x00;
P4DIR = 0xFF;
P5SEL = 0x00;
P5DIR|= BIT0 + BIT1 + BIT5 + BIT6 + BIT7;
PSB_SET; //LCD parallel port mode
RST_SET; //Reset pin RST set high
}
//***********************************************************************
// Display command write function
//***********************************************************************
void LCD_write_com(unsigned char com)
{
RS_CLR;
RW_CLR;
EN_SET;
DataPort = com;
delay_ms(5); 0x01); delay_ms(5); } //****************************************************************************
// Display screen data write function //*********************************************************************** void LCD_write_data(unsigned char data) { RS_SET; RW_CLR; EN_SET; DataPort = data; delay_ms(5); EN_CLR; } //*************************************************************************** // Display screen clears display //*************************************************************************** void LCD_clear(void) { LCD_write_com(0x01); delay_ms(5); } //*************************************************************************** //Function name: DisplayCgrom(uchar hz) displays Chinese characters in CGROM //******************************************************************************* void DisplayCgrom(uchar addr,uchar *hz) { LCD_write_com(addr); delay_ms(5); while(*hz != '\0') { LCD_write_data(*hz); hz++; delay_ms(5); } } //******************************************************************** // Display screen initialization function //*************************************************************************** void LCD_init(void) { LCD_write_com(FUN_MODE); //Display mode setting delay_ms(5); LCD_write_com(FUN_MODE); //Display mode setting delay_ms(5); LCD_write_com(DISPLAY_ON); //Display on delay_ms(5); LCD_write_com(CLEAR_SCREEN); //Clear screen delay_ms(5); } //********************************************************************* //***************************************************************** /*Turn on ADC*/ void ADC12(void) {






















































P6SEL |= 0X0f; // Enable ADC channel
ADC12CTL0 = ADC12ON + SHT0_15 + MSC; // Turn on ADC, set sampling time, multiple conversions
ADC12CTL1 = SHP + CONSEQ_3; // Use sampling timer; Multi-channel conversion
ADC12MCTL0 |= INCH_0; // Channel selection
ADC12MCTL1 |= INCH_1;
ADC12MCTL2 |= INCH_2;
ADC12MCTL3 |= INCH_10 + EOS; // End the conversion with EOS
ADC12IE = 0X0F; // Enable ADC interrupt
ADC12CTL0 |= ENC + ADC12SC; // Enable conversion; Start conversion
_EINT();
}
/* ADC interrupt service function, storage of conversion values of each channel */
#pragma vector = ADC_VECTOR
__interrupt void ADC12ISR(void)
{
caltmp[0] = ADC12MEM0;
caltmp[1]=ADC12MEM1;
caltmp[2]=ADC12MEM2;
caltmp[3]=ADC12MEM3;
}
//************************************************************************
void xian_shi(void)
{
int i,j,k,l;
Temp=(caltmp[0]*3300)/4095;//Calculate the decimal voltage value
ptr[0]=Temp/1000;
ptr[2]=Temp%1000/100;
ptr[3]=Temp%100/10;
ptr[4]=Temp%10;
ptr[5]=11;
ptr[1]=10;
LCD_write_com(0x80);
DisplayCgrom(0x80,"Voltage of one channel");
for(i=0;i<6;i++)
{
delay_ms(10);
LCD_write_data(shuzi[ptr]);
}
Temp=(caltmp[1]*3300)/4095; ptr
[0]=Temp/1000;
ptr[2]=Temp%1000/100;
ptr[3]=Temp%100/10 ; ptr [
4]=Temp%10 ; ptr [5]
=11; ptr[1]=10 ; LCD_write_com ( 0 } ptr[3]=Temp%100/10; ptr[4]=Temp%10; ptr[5]=11; ptr[1]=10; LCD_write_com(0x88); DisplayCgrom(0x88,"Three channel voltage"); for(k=0;k<6;k++) { delay_ms(10); LCD_write_data(shuzi[ptr[k]]); } Temp=(caltmp[3]*3300)/4095; ptr[0]=Temp/1000; ptr[2]=Temp%1000/100; ptr[3]=Temp%100/10; ptr[4]=Temp%10; ptr[5]=11; ptr[1]=10; LCD_write_com(0x98); DisplayCgrom(0x98,"Four channel voltage"); for(l=0;l<6;l++) { delay_ms(10); LCD_write_data(shuzi[ptr[l]]); } } //*********************************************************************** // Main program //*********************************************************************** void main(void) { WDT_Init(); //Watchdog settingsClock_Init (); //System clock settingsPort_init (); //System initialization, set IO port propertiesdelay_ms (100); //Delay 100ms














































LCD_init(); //LCD parameter initialization settings
LCD_clear(); //Clear screen
delay_ms(100);
while(1)
{
ADC12();
delay_ms(10);
xian_shi();
}
}

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

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