john120
Banned
- Joined
- Aug 13, 2011
- Messages
- 257
- Helped
- 11
- Reputation
- 22
- Reaction score
- 10
- Trophy points
- 1,298
- Activity points
- 0
You need to put a function prototype at the beginning of the file so that main knows what parameters the function takes.
/*--- Function prototypes ---*/
void tempdisplay(void);
void messagedisplay(void);
/*--- Start of program ---*/
void main(void)
{
//code
}
If you wrote the code for main after the other functions it would be ok as well.
Main can't see the other functions that come after it. It can't forward reference.
Also
void float messagedisplay() ???
You cant return void and float.
Post your full code and I will fix it.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 if(input(PIN_B4)==1) { delay_ms(30); if(input(PIN_B4)==1) { display temperature display period of a square wave signal read on CCP1; } } if(input(PIN_B3)==1) { delay_ms(30); if(input(PIN_B3)==1) { display other message for example:"How are you" } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 #include <16F877A.h> #DEVICE ADC=10 #fuses HS,NOWDT,NOPROTECT,NOLVP #use delay(clock=20000000) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) #include "lcd.c" void tempdisplay(); void messagedisplay(); int1 flag; float voltsf, MR; long rise1, rise2, period; unsigned int adc_value, volts; #int_ccp1 void isr() { if (flag==0) { rise1 = CCP_1; flag=1; } else if (flag==1) { rise2 = CCP_1; period=(rise2-rise1); flag=0; } } void tempdisplay() { volts = 0; adc_value = read_adc(); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts = volts/5; voltsf=(volts*1.8)+32; } void messagedisplay() { delay_us(200); printf(lcd_putc,"\fWELCOME"); delay_ms(500); printf(lcd_putc,"\fTO"); delay_ms(500); printf(lcd_putc, "\fPIC 16F877A", ); delay_ms(500); printf(lcd_putc, "\fPROGRAMMING"); } void main(void) { flag=0; lcd_init(); lcd_gotoxy(1,1); delay_us(200); printf(lcd_putc, "\fPIC 16F877A", ); delay_ms(500); printf(lcd_putc, "\fPROGRAMMING"); setup_adc_ports(AN0); setup_adc(ADC_CLOCK_INTERNAL); set_adc_channel(0); setup_ccp1(CCP_CAPTURE_RE|CCP_CAPTURE_DIV_16); // Configure CCP1 to capture rise setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); // Start timer 1 enable_interrupts(INT_CCP1); // Setup interrupt on risining edge enable_interrupts(GLOBAL); disable_interrupts(global); delay_ms(300); while(1){ tempdisplay(); if(input(PIN_B4)==1) { delay_ms(30); if(input(PIN_B4)==1) { //display temperature printf(lcd_putc, "\f%7.4f\r\n", voltsf); //display period of a square wave signal read on CCP1; printf(lcd_putc, "\f%5lu\r\n", period); } } if(input(PIN_B3)==1) { delay_ms(30); if(input(PIN_B3)==1) { messagedisplay(); } } } }
What is your new problem?
button code.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 if(input(PIN_B4)==1) { delay_ms(30); if(input(PIN_B4)==1) { display temperature display period of a square wave signal read on CCP1; } } if(input(PIN_B3)==1) { delay_ms(30); if(input(PIN_B3)==1) { display other message for example:"How are you" } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 #include <16F877A.h> #DEVICE ADC=10 #fuses HS,NOWDT,NOPROTECT,NOLVP #use delay(clock=20000000) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) #include "lcd.c" void tempdisplay(); void messagedisplay(); int1 flag; float voltsf, MR; long rise1, rise2, period; unsigned int adc_value, volts; #int_ccp1 void isr() { if (flag==0) { rise1 = CCP_1; flag=1; } else if (flag==1) { rise2 = CCP_1; period=(rise2-rise1); flag=0; } } void tempdisplay() { volts = 0; adc_value = read_adc(); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts = volts/5; voltsf=(volts*1.8)+32; } void messagedisplay() { delay_us(200); printf(lcd_putc,"\fWELCOME"); delay_ms(500); printf(lcd_putc,"\fTO"); delay_ms(500); printf(lcd_putc, "\fPIC 16F877A", ); delay_ms(500); printf(lcd_putc, "\fPROGRAMMING"); } void main(void) { flag=0; lcd_init(); lcd_gotoxy(1,1); delay_us(200); printf(lcd_putc, "\fPIC 16F877A", ); delay_ms(500); printf(lcd_putc, "\fPROGRAMMING"); setup_adc_ports(AN0); setup_adc(ADC_CLOCK_INTERNAL); set_adc_channel(0); setup_ccp1(CCP_CAPTURE_RE|CCP_CAPTURE_DIV_16); // Configure CCP1 to capture rise setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); // Start timer 1 enable_interrupts(INT_CCP1); // Setup interrupt on risining edge enable_interrupts(GLOBAL); disable_interrupts(global); delay_ms(300); while(1){ tempdisplay(); if(input(PIN_B4)==1) { delay_ms(30); if(input(PIN_B4)==1) { //display temperature printf(lcd_putc, "\f%7.4f\r\n", voltsf); //display period of a square wave signal read on CCP1; printf(lcd_putc, "\f%5lu\r\n", period); } } if(input(PIN_B3)==1) { delay_ms(30); if(input(PIN_B3)==1) { messagedisplay(); } } } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 #include <16F877A.h> #DEVICE ADC=10 #fuses HS,NOWDT,NOPROTECT,NOLVP #use delay(clock=20000000) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) #include "lcd.c" void tempdisplay(); void messagedisplay(); int1 flag; float voltsf, MR; long rise1, rise2, period; unsigned int adc_value, volts; #int_ccp1 void isr() { if (flag==0) { rise1 = CCP_1; flag=1; } else if (flag==1) { rise2 = CCP_1; period=(rise2-rise1); flag=0; } } void tempdisplay() { volts = 0; adc_value = read_adc(); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts = volts/5; voltsf=(volts*1.8)+32; } void messagedisplay() { delay_us(200); printf(lcd_putc,"\fWELCOME"); delay_ms(500); printf(lcd_putc,"\fTO"); delay_ms(500); printf(lcd_putc, "\fPIC 16F877A", ); delay_ms(500); printf(lcd_putc, "\fPROGRAMMING"); } void main(void) { flag=0; lcd_init(); lcd_gotoxy(1,1); delay_us(200); printf(lcd_putc, "\fPIC 16F877A", ); delay_ms(500); printf(lcd_putc, "\fPROGRAMMING"); setup_adc_ports(AN0); setup_adc(ADC_CLOCK_INTERNAL); set_adc_channel(0); setup_ccp1(CCP_CAPTURE_RE|CCP_CAPTURE_DIV_16); // Configure CCP1 to capture rise setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); // Start timer 1 enable_interrupts(INT_CCP1); // Setup interrupt on risining edge enable_interrupts(GLOBAL); disable_interrupts(global); delay_ms(300); while(1){ tempdisplay(); if(input(PIN_B4)==1) { delay_ms(30); if(input(PIN_B4)==1) { //display period of a square wave signal read on CCP1; printf(lcd_putc, "\f%5lu\r\n", period); delay_ms(3000); //display temperature if((voltsf > 5) && (voltsf < 10)){ printf(lcd_putc, "\f15\r\n"); } else if((voltsf > 10) && (voltsf < 12)){ printf(lcd_putc, "\f18\r\n"); } else if((voltsf > 12) && (voltsf < 15)){ printf(lcd_putc, "\f65\r\n"); } } } if(input(PIN_B3)==1) { delay_ms(30); if(input(PIN_B3)==1) { messagedisplay(); delay_ms(3000); //display period of a square wave signal read on CCP1; printf(lcd_putc, "\f%5lu\r\n", period); delay_ms(3000); //display temperature if((voltsf > 5) && (voltsf < 10)){ printf(lcd_putc, "\f15\r\n"); } else if((voltsf > 10) && (voltsf < 12)){ printf(lcd_putc, "\f18\r\n"); } else if((voltsf > 12) && (voltsf < 15)){ printf(lcd_putc, "\f65\r\n"); } } } } }
Your CCPx capture code to get the pulse period is wrong. You have disabled the interrupts. You won't get the value of Period. I don't know CCS C much, So, you have to find solution for period thing yourself.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 #include <16F877A.h> #DEVICE ADC=10 #fuses HS,NOWDT,NOPROTECT,NOLVP #use delay(clock=20000000) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) #include "lcd.c" void tempdisplay(); void messagedisplay(); int1 flag; float voltsf, MR; long rise1, rise2, period; unsigned int adc_value, volts; #int_ccp1 void isr() { if (flag==0) { rise1 = CCP_1; flag=1; } else if (flag==1) { rise2 = CCP_1; period=(rise2-rise1); flag=0; } } void tempdisplay() { volts = 0; adc_value = read_adc(); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts += ((float)(adc_value * 500)/1023.0); delay_ms(10); volts = volts/5; voltsf=(volts*1.8)+32; } void messagedisplay() { delay_us(200); printf(lcd_putc,"\fWELCOME"); delay_ms(500); printf(lcd_putc,"\fTO"); delay_ms(500); printf(lcd_putc, "\fPIC 16F877A", ); delay_ms(500); printf(lcd_putc, "\fPROGRAMMING"); } void main(void) { flag=0; lcd_init(); lcd_gotoxy(1,1); delay_us(200); printf(lcd_putc, "\fPIC 16F877A", ); delay_ms(500); printf(lcd_putc, "\fPROGRAMMING"); setup_adc_ports(AN0); setup_adc(ADC_CLOCK_INTERNAL); set_adc_channel(0); setup_ccp1(CCP_CAPTURE_RE|CCP_CAPTURE_DIV_16); // Configure CCP1 to capture rise setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); // Start timer 1 enable_interrupts(INT_CCP1); // Setup interrupt on risining edge enable_interrupts(GLOBAL); disable_interrupts(global); delay_ms(300); while(1){ tempdisplay(); if(input(PIN_B4)==1) { delay_ms(30); if(input(PIN_B4)==1) { //display period of a square wave signal read on CCP1; printf(lcd_putc, "\f%5lu\r\n", period); delay_ms(3000); //display temperature if((voltsf > 5) && (voltsf < 10)){ printf(lcd_putc, "\f15\r\n"); } else if((voltsf > 10) && (voltsf < 12)){ printf(lcd_putc, "\f18\r\n"); } else if((voltsf > 12) && (voltsf < 15)){ printf(lcd_putc, "\f65\r\n"); } } } if(input(PIN_B3)==1) { delay_ms(30); if(input(PIN_B3)==1) { messagedisplay(); delay_ms(3000); //display period of a square wave signal read on CCP1; printf(lcd_putc, "\f%5lu\r\n", period); delay_ms(3000); //display temperature if((voltsf > 5) && (voltsf < 10)){ printf(lcd_putc, "\f15\r\n"); } else if((voltsf > 10) && (voltsf < 12)){ printf(lcd_putc, "\f18\r\n"); } else if((voltsf > 12) && (voltsf < 15)){ printf(lcd_putc, "\f65\r\n"); } } } } }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?