2597 views|5 replies

34

Posts

0

Resources
The OP

There is a problem with the program copied from elsewhere. Please help [Copy link]

******************************************************Part 1**************************************************** /******************************************************** Program function: The ADC on the MCU converts the voltage of the P6.0 port and displays the analog voltage value on the 1602 LCD. ---------------------------------------------------------- Dip switch setting: turn the LCD bit to ON and the rest to OFF Test description: adjust the knob of potentiometer W1 and observe the digital changes on the LCD display. ***********************************************************/ #include  
WDTCTL = WDTPW+WDTHOLD; //Turn off the watchdog /*The following six lines of program turn off all IO ports*/ P1DIR = 0XFF;P1OUT = 0XFF; P2DIR = 0XFF;P2OUT = 0XFF; P3DIR = 0XFF;P3OUT = 0XFF; P4DIR = 0XFF;P4OUT = 0XFF; P5DIR = 0XFF;P6DIR = 0XFF;P7DIR = 0XFF;P8DIR = 0XFF;P9DIR = 0XFF;P10DIR = 0XFF;P11DIR = 0XFF;P12DIR = 0XFF;P13DIR = 0XFF;P14DIR = 0XFF;P15DIR = 0XFF;P16DIR = 0XFF;P17DIR = 0XFF;P18DIR = 0XFF;P19DIR = 0XFF;P20DIR = 0XFF;P21DIR = 0XFF;P22DIR = 0XFF;P23DIR = 0XFF;P34DIR = 0XFF;P35DIR = 0XFF;P36DIR = 0XFF;P37DIR = 0XFF;P38DIR = 0XFF;P39DIR = 0XFF;P40DIR = 0XFF;P41DIR = 0XFF;P42DIR = 0XFF;P43DIR = 0 0XFF;P3OUT = 0XFF; P4DIR = 0XFF;P4OUT = 0XFF; P5DIR = 0XFF;P5OUT = 0XFF; P6DIR = 0XFF;P6OUT = 0XFF; P6DIR |= BIT2;P6OUT |= BIT2; //Turn off level conversion LcdReset(); //Reset 1602 LCD DispNChar(2,0,12,tishi); //Display prompt information Disp1Char(11,1,'V'); //Display voltage unit P6SEL |= 0x01; //Enable ADC channel ADC12CTL0 = ADC12ON+SHT0_8+MSC; //Turn on ADC and set sampling time ADC12CTL1 = SHP+CONSEQ_2; //Use sampling timer ADC12IE = 0x01; //Enable ADC interrupt ADC12CTL0 |= ENC; // Enable conversion ADC12CTL0 |= ADC12SC; // Start conversion _EINT(); LPM0; } /******************************************* Function name: ADC12ISR Function: ADC interrupt service function, here use multiple averages to calculate the analog voltage value of P6.0 port Parameter: None Return value: None **************************************************/ #pragma vector=ADC12_VECTOR __interrupt void ADC12ISR (void) { static uint index = 0; results[index++] = ADC12MEM0; // Move results if(index == Num_of_Results) { uchar i; unsigned long sum = 0; index = 0; for(i = 0; i < Num_of_Results; i++) { sum += results[i]; } sum >>= 5; // Divide by 32 Trans_val(sum); } } /*********************************************** Function name: Trans_val Function: Convert the hexadecimal ADC conversion data into three-digit decimal real analog voltage data and display it on the LCD Parameter: Hex_Val--hexadecimal data n--the denominator during conversion is equal to 2 to the power of n Return value: None **********************************************/ void Trans_val(uint Hex_Val) { unsigned long caltmp; uint Curr_Volt; uchar t1,i; uchar ptr[4]; caltmp = Hex_Val; caltmp = (caltmp << 5) + Hex_Val; //caltmp = Hex_Val * 33 caltmp = (caltmp << 3) + (caltmp << 1); //caltmp = caltmp * 10 Curr_Volt = caltmp >> 12; //Curr_Volt = caltmp / 2^n ptr[0] = Curr_Volt / 100; //Hex->Dec conversion t1 = Curr_Volt - (ptr[0] * 100); ptr[2] = t1 / 10; ptr[3] = t1 - (ptr[2] * 10); ptr[1] = 10; //The 10th bit in the shuzi table corresponds to the symbol "." //Display the result of the conversion on the LCD for(i = 0;i < 4;i++) Disp1Char((6 + i),1,shuzi[ptr[i]]); } ***********************************************Part 2******************************************************* #include
#include "cry1602.h" typedef unsigned char uchar; typedef unsigned int uint; /**************Macro definition******************/ #define DataDir P4DIR #define DataPort P4OUT #define Busy 0x80 #define CtrlDir P3DIR #define CLR_RS P3OUT&=~BIT0; //RS = P3.0 #define SET_RS P3OUT|=BIT0; #define CLR_RW P3OUT&=~BIT1; //RW = P3.1 #define SET_RW P3OUT|=BIT1; #define CLR_EN P3OUT&=~BIT2; //EN = P3.2 #define SET_EN P3OUT|=BIT2 ; /****************************************** Function name: DispNchar Function: Let the LCD display N characters continuously from a certain position Parameters: x--column coordinate of the position y--row coordinate of the position n--number of characters ptr--pointer to the character storage position Return value: None* **********************************************/ void DispNChar(uchar x, uchar y, uchar n,uchar *ptr) { uchar i; for (i=0;i
This error will occur in IAR

Delay400ms is implemented in both cry1604 and main. The global symbol has multiple definitions. This doesn't work in IAR or anywhere else in your program. You need to delete one.

[quote][size=2][url=forum.php?mod=redirect&goto=findpost&pid=1655418&ptid=433666][color=#999999]sjtitr posted on 2014-4-2 09:21[/color][/url][/size] Delay400ms is implemented in both cry1604 and main. The global symbol has multiple definitions. This doesn't work in IAR or anywhere else in your program. You need to delete one of them. [/quote] Yes, I checked online and it says there is a duplication. Can the master tell me how to delete it and modify it? Sorry for the trouble.

It is not recommended to copy other people's programs. It is generally difficult to understand other people's programs better. First try ADC conversion, then try 1602 LCD display, and then combine the two together. You will have a deeper understanding if you do it yourself...

[quote][size=2][url=forum.php?mod=redirect&goto=findpost&pid=1655425&ptid=433666][color=#999999]gh131413 posted on 2014-4-2 09:36[/color][/url][/size] It is not recommended to copy other people's programs. It is generally impossible to understand other people's programs better. First try ADC conversion, then try 1602 LCD display, and then combine the two...[/quote] Well, it is better to do it by myself. Indeed, my programming ability is very limited. Now time is very tight. I want to take a look at the phenomenon, otherwise the mid-term will be here soon, which is worrying!

There is a problem with the program copied from elsewhere. Please help


This post is from Microcontroller MCU

Latest reply

It is not recommended to copy other people's programs. It is generally difficult to understand other people's programs better. First try ADC conversion, then try 1602 LCD display, and then combine the two together. You will have a deeper understanding if you do it yourself...  Details Published on 2014-4-2 09:36
Personal signaturelet us go

34

Posts

0

Resources
2
This error will occur in IAR

无标题.png (10.98 KB, downloads: 0)

会出现这样的错误

会出现这样的错误
This post is from Microcontroller MCU
Personal signaturelet us go

658

Posts

2

Resources
3
Delay400ms is implemented in both cry1604 and main. The global symbol has multiple definitions. This doesn't work in IAR or anywhere else in your program. You need to delete one.
This post is from Microcontroller MCU

Comments

Well, I checked online and it said there is a meaning of duplication. Can the master tell me how to delete it and modify it?  Details Published on 2014-4-2 09:25
Personal signature

非遗古法手工编程


34

Posts

0

Resources
4
sjtitr posted on 2014-4-2 09:21 Delay400ms is implemented in both cry1604 and main. The global symbol has multiple definitions. This doesn't work in IAR or anywhere else in your program. You need to delete one of them.
Yes, I checked online and it says there is a duplication. Can the master tell me how to delete it and modify it? Sorry for the trouble.
This post is from Microcontroller MCU
Personal signaturelet us go

1291

Posts

0

Resources
5
It is not recommended to copy other people's programs. It is generally difficult to understand other people's programs better. First try ADC conversion, then try 1602 LCD display, and then combine the two together. You will have a deeper understanding if you do it yourself...
This post is from Microcontroller MCU

Comments

Well, I did a good job. My programming ability is indeed very limited. Now I am very pressed for time and want to see the results. Otherwise, the mid-term exam will be here soon, which will be really worrying!  Details Published on 2014-4-2 09:42

34

Posts

0

Resources
6
gh131413 posted on 2014-4-2 09:36 It is not recommended to copy other people's programs. It is generally impossible to understand other people's programs better. First try ADC conversion, then try 1602 LCD display, and then combine the two...
Well, it is better to do it by myself. Indeed, my programming ability is very limited. Now time is very tight. I want to take a look at the phenomenon, otherwise the mid-term will be here soon, which is worrying!
This post is from Microcontroller MCU
Personal signaturelet us go

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

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