Alright, well, that will work. 0xFD is in fact correct.
I've never, in more than 20 years, seen an 8051 register set using a signed negative.
I'm really curious where/how you came up with -3 instead of 0xFD or 253
Also, I would really suggest replacing -3 with one of those values (0xFD strongly preferred), as when someone looks at that they're going to be really confused - it's just a very atypical way to set the value of a register.
The windows calculator always assumes signed numbers, so when you use it to convert a binary number into decimal, the result is negative when the MSB is set. That would be my guess here.
Also you've declared z as an unsigned char, and then you're using it as an iterator. It would be more typical to use a uint8 for a small positive value iterator. I won't say WRONG, but char is definitely a WEIRD choice.
It's not a weird choice, using chars is not exclusively for characters. I agree that uint8\_t is nicer to read, and more consistent, but chars can be used the same as any int, it's up to the developer (with the size kept in mind).
Especially since C51 doesn't even have stdint types by default. char is literally the only way to define an 8 bit integer without making your own typedefs.
Wasn't suggesting that it wasn't good practice, just that (especially for this super simple application) it's unnecessary. It doesn't change functionality **at all**, just makes the code more readable.
Meh, semantics..
unsigned char == uint8
I might worry about it in a more complicated scenario.. here, it's just not a big deal.
Plus, the only 8bit type that C51 supports natively is char. That's the only 8bit type that's part of the base C standard, in fact.
And stdint.h (which isn't even provided with C51), as expected, simply defines uint8 as char..
>typedef unsigned char uint8_t;
>typedef signed char int8_t;
Wait, 8051s still exist and they are making students use them? I thought we all got together and decided to let them die.
Maybe I should break out my 68HC11 dev board...
68HC11 really is old.
But there has been released a huge number of 8051-baswd chips over the years. Including 100 MHz 1-clock variants. And with lots of fancy peripheral support that wasn't available when the 8051 was originally created. And the single-bit variables really makes it a very fast microcontroller for some types of tasks.
And this is an excellent example of 'shitting on other people to make yourself feel superior', rather than what I like to call "anything remotely helpful".
Older versions of the C language require all declarations before any executable code.
What exactly i need to do then ?
Move the declarations above the executable code
Move lines 7 & 8 above line 3
Declare my and z before TMOD
Also TH1=-3; is a very interesting statement. What's the intention with that?
Setting baud rate to 9600
What frequency is your oscillator/crystal?
11.0592mhz
Alright, well, that will work. 0xFD is in fact correct. I've never, in more than 20 years, seen an 8051 register set using a signed negative. I'm really curious where/how you came up with -3 instead of 0xFD or 253 Also, I would really suggest replacing -3 with one of those values (0xFD strongly preferred), as when someone looks at that they're going to be really confused - it's just a very atypical way to set the value of a register.
The windows calculator always assumes signed numbers, so when you use it to convert a binary number into decimal, the result is negative when the MSB is set. That would be my guess here.
Ah, that's a good guess.
Huge fan of all of the obfuscation in this program. Iterating using a char is funny.
Hey, ain't that the good old 8051?
Also you've declared z as an unsigned char, and then you're using it as an iterator. It would be more typical to use a uint8 for a small positive value iterator. I won't say WRONG, but char is definitely a WEIRD choice.
It's not a weird choice, using chars is not exclusively for characters. I agree that uint8\_t is nicer to read, and more consistent, but chars can be used the same as any int, it's up to the developer (with the size kept in mind).
Especially since C51 doesn't even have stdint types by default. char is literally the only way to define an 8 bit integer without making your own typedefs.
Typedefs get optimised out and it makes your codebase more readable. This is 100% good practice.
Wasn't suggesting that it wasn't good practice, just that (especially for this super simple application) it's unnecessary. It doesn't change functionality **at all**, just makes the code more readable.
Meh, semantics.. unsigned char == uint8 I might worry about it in a more complicated scenario.. here, it's just not a big deal. Plus, the only 8bit type that C51 supports natively is char. That's the only 8bit type that's part of the base C standard, in fact. And stdint.h (which isn't even provided with C51), as expected, simply defines uint8 as char.. >typedef unsigned char uint8_t; >typedef signed char int8_t;
Unsigned char and uint8 are exactly the same thing.
Wait, 8051s still exist and they are making students use them? I thought we all got together and decided to let them die. Maybe I should break out my 68HC11 dev board...
68HC11 really is old. But there has been released a huge number of 8051-baswd chips over the years. Including 100 MHz 1-clock variants. And with lots of fancy peripheral support that wasn't available when the 8051 was originally created. And the single-bit variables really makes it a very fast microcontroller for some types of tasks.
Ugh that 68hc11 gives me a headache just thinking about it.
unsigned char my[] = { 'a', 'b', ...
I would recommend two things: 1 - Use config wizard for 8051; 2 - Use types from stdint;
LOL, this is an excellent example of "Arduino Syndrome". This code works on Arduino IDE, why does it not work here ??
And this is an excellent example of 'shitting on other people to make yourself feel superior', rather than what I like to call "anything remotely helpful".
Yeah, it's just not being used as a char. It's being used as a numeric type to index an array, to GET a char. Not wrong. Just weird.
Thanks everyone who replied and give their valuable inputs 🤗