|
|
View previous topic :: View next topic |
Author |
Message |
Ibrahim_kh
Joined: 11 May 2023 Posts: 2
|
I need help to fix an error in my small code |
Posted: Thu May 11, 2023 11:25 am |
|
|
*** Error 51 "labC3.c" Line 43(15,20): A numeric expression must appear here
Code: | #DEVICE PIC16F628A
#use delay(clock = 4000000)
#fuses INTRC_IO, NOWDT, PUT
#include "LCD.h"
#include "16F628A.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void scrollText1(char* text) {
int len = strlen(text);
int i, j;
// Loop to scroll the text
for (i = 0; i <= len - 16; i++) {
lcd_init();
lcd_gotoxy(1,1); // Set cursor position to the beginning of the first line
// Write the current 16 characters of the text to the LCD
for (j = 0; j < 16; j++) {
lcd_putc(text[i + j]);
delay_ms(10);
}
// Replace the above code with the following:
char substring[17];
strncpy(substring, text + i, 16);
substring[16] = '\0';
lcd_putc(substring);
}
delay_ms(500); // Delay to control scrolling speed
}
void main()
{
const char* SENTENCE = "Thank you for programming me!!";
delay_ms(10);
scrollText1(SENTENCE); ////////////LINE51 WHERE THERE IS ERROR
while(1){};
}
|
|
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Thu May 11, 2023 11:58 am |
|
|
By cleaning up your header lines (deleting the #include 628A.h line, fixing the
#DEVICE line and fixing the LCD.h line).
Code: |
#DEVICE PIC16F628A <<<<<<<<<< One Device line (deleted the .h file line)
#use delay(clock = 4000000)
#fuses INTRC_IO, NOWDT, PUT
#include <LCD.c> <<<<<< Changed to LCD.c <<<<<<<
|
Made no other changes in the rest of the code and it now compiles under 5.115
Didn't look for any other issues. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Fri May 12, 2023 2:09 am |
|
|
Better really to use the #include line.
But put it where shown by dyeatman:
Code: |
#include "16F628A.h" //The include has the device definition in it
#use delay(clock = 4000000)
#fuses INTRC_IO, NOWDT, PUT
#include <LCD.c> <<<<<< Changed to LCD.c <<<<<<<
|
Using the #include adds the definitions for lots of things, and if you don't
have these there will be problems with anything more complex.
The key point though is that the processor definition _must_ always come
before almost anything else. Otherwise the compiler does not know what
you actually want it to do, and the processor can only be set _once_.
Even with the code as shown, if you don't have the #include, you don't
have models for any form of debugging. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|