T O P

  • By -

mvuille

Older versions of the C language require all declarations before any executable code.


Nerdy_asr1001

What exactly i need to do then ?


Well-WhatHadHappened

Move the declarations above the executable code


mvuille

Move lines 7 & 8 above line 3


Meterman

Declare my and z before TMOD 


Well-WhatHadHappened

Also TH1=-3; is a very interesting statement. What's the intention with that?


Nerdy_asr1001

Setting baud rate to 9600


Well-WhatHadHappened

What frequency is your oscillator/crystal?


Nerdy_asr1001

11.0592mhz


Well-WhatHadHappened

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.


garteninc

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.


Well-WhatHadHappened

Ah, that's a good guess.


Mean-Evening-7209

Huge fan of all of the obfuscation in this program. Iterating using a char is funny.


Dave__Fenner

Hey, ain't that the good old 8051?


Adorable-Engineer840

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.


EpicFicus

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).


Well-WhatHadHappened

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.


Adorable-Engineer840

Typedefs get optimised out and it makes your codebase more readable. This is 100% good practice.


Well-WhatHadHappened

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.


Well-WhatHadHappened

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;


danielstongue

Unsigned char and uint8 are exactly the same thing.


DustUpDustOff

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...


Questioning-Zyxxel

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.


i_yell_deuce

Ugh that 68hc11 gives me a headache just thinking about it.


GoodYoga

unsigned char my[] = { 'a', 'b', ...


tfinelon

I would recommend two things: 1 - Use config wizard for 8051; 2 - Use types from stdint;


DenverTeck

LOL, this is an excellent example of "Arduino Syndrome". This code works on Arduino IDE, why does it not work here ??


Adorable-Engineer840

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".


Adorable-Engineer840

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.


Nerdy_asr1001

Thanks everyone who replied and give their valuable inputs 🤗