We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
i cant find any prewitten code and chat gpt doesnt do the job properly.
this is what i have so far from chat gpt:
#include <REG51.H> unsigned char code memory_data[1024] = { // Optional data for testing 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, // Continue filling if needed }; void main(void) { unsigned int address; unsigned char data; unsigned char code *ptr; while (1) { // Read address from P1 (high byte) and P0 (low byte) address = ((unsigned int)P1 << 8) | P0; // Check if address is in bounds if (address < 1024) { ptr = memory_data + address; // pointer into code memory data = *ptr; // read from code memory } else { data = 0xFF; // Invalid address } // Output data to Port 2 P2 = data; } }
although this contains alot of errors.
dd.c(11): error C141: syntax error near ';', expected '<id>'dd.c(12): error C141: syntax error near 'unsigned', expected '__asm'dd.c(20): error C202: 'ptr': undefined identifierdd.c(21): error C141: syntax error near 'data', expected '__asm'dd.c(21): error C202: 'ptr': undefined identifierdd.c(23): error C141: syntax error near '=', expected 'hdata'dd.c(27): error C141: syntax error near 'data', expected 'sizeof'
any ideas?
what does that mean?
The C51 has some reserved words that specify a memory type. Please see:
https://developer.arm.com/documentation/101655/0961/Cx51-User-s-Guide/Language-Extensions/Memory-Types
So rename 'data' to any other name.
What I don't understand is: You write you want to read a 12 bit memory address, but you limit the value to 1024. In my world, these are 10 bits and I would mask the bits read from P1. Only a suggestion.
the program is wrong. it was written with ai. i need 4096 bytes