I want to check if my microcontroller is working. It's the first time I'm working with microcontrollers. I followed this tutorial to blink a LED at the P1.0 pin, but nothing is happening.
My microcontroller is AT89S51. My operating system is macOS Ventura. I'm using Arduino Leonardo as an ISP programmer. Using BC548 transistor.
My Assembly code:
; Blink an LED connected to Pin P1.0 every second
ORG 0H
; set P1.0 as output
MOV P1, #00000001B
LOOP: ; turn on LED
SETB P1.0
; delay for 500ms
ACALL DELAY
; turn off LED
CLR P1.0
; delay for 500ms
ACALL DELAY
; jump back to the beginning of the loop
JMP LOOP
DELAY: ; delay for 500ms
MOV R1, #10
MOV R2, #200
DELAY_LOOP:
DJNZ R1, $
DJNZ R2, DELAY_LOOP
RET
END
Creating .hex file:
@~ : c51asm blink.asm
C51ASM: advanced C51 macro assembler Version 1.2 (06 May 2011)
Copyright (C) 2011 Atmel Corp.
Pass 1 completed with no warnings and no errors
Pass 2 completed with no warnings and no errors
Segment usage:
Code : 22 bytes
Data : 0 bytes
Idata : 0 bytes
Edata : 0 bytes
Fdata : 0 bytes
Xdata : 0 bytes
Bit : 0 bits
Register banks used: ---
Warnings: 0
Errors: 0
Writing into the microcontroller flash memory, where the file F40R96CIUSLFZFP.conf is defined here:
@~ : avrdude -C ~/micro/F40R96CIUSLFZFP.conf -c stk500v1 -P /dev/cu.usbmodem1101 -p 89s51 -b 19200 -U flash:w:/Users/me/blink.hex
Output:
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e5106 (probably 89s51)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "/Users/me/blink.hex"
avrdude: input file /Users/me/blink.hex auto detected as Intel Hex
avrdude: writing flash (68 bytes):
Writing | ################################################## | 100% 0.14s
avrdude: 68 bytes of flash written
avrdude: verifying flash memory against /Users/me/blink.hex:
avrdude: input file /Users/me/blink.hex auto detected as Intel Hex
Reading | ################################################## | 100% 0.05s
avrdude: 68 bytes of flash verified
avrdude done. Thank you.
Everything seems to be fine, but nothing happens (LED is not blinking). I don't know if I'm supposed to connect or disconnect something after the upload, but I guess it should start blinking right away(?). My connection images are below (although I've triple-checked).
-
1\$\begingroup\$ It's impossible to see how the LED is connected and where, to see if there are any mistakes. \$\endgroup\$Justme– Justme2023年04月18日 13:12:17 +00:00Commented Apr 18, 2023 at 13:12
-
2\$\begingroup\$ Just try moving LED to the opposite power rail (to ground instead of V+). \$\endgroup\$Edin Fifić– Edin Fifić2023年04月18日 13:32:32 +00:00Commented Apr 18, 2023 at 13:32
-
1\$\begingroup\$ @Justme You're right, LED seems to be reversed. \$\endgroup\$Edin Fifić– Edin Fifić2023年04月18日 13:33:35 +00:00Commented Apr 18, 2023 at 13:33
-
2\$\begingroup\$ @ludicrous No, I don't think you should delete the question, but I would leave that up to the moderators. The point of SE is to share problems and solutions, and yours is a good example too. It shows how much we can go into details while it can be completely something else and just a simple mistake which makes it seem to not work after all the time, effort and knowledge invested. \$\endgroup\$Edin Fifić– Edin Fifić2023年04月18日 13:44:29 +00:00Commented Apr 18, 2023 at 13:44
-
3\$\begingroup\$ Just write your result up as an answer, it is perfectly fine to write an answer to your own question. And saying: the code is fine but I wired my circuit wrong (please describe with some detail) is also helpful. \$\endgroup\$Arsenal– Arsenal2023年04月18日 14:03:11 +00:00Commented Apr 18, 2023 at 14:03
1 Answer 1
SOLVED: Turns out that my microcontroller is working and the code is fine. The issue has to do with the circuit itself, I overlooked the fact that the LED is in reverse bias - so, of course, no current was passing through.
-
\$\begingroup\$ Hint: The larger metal part inside the LED, holding the LED chip, is the cathode except it is an infrared LED. \$\endgroup\$Jens– Jens2023年04月19日 02:02:07 +00:00Commented Apr 19, 2023 at 2:02
Explore related questions
See similar questions with these tags.