Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PICprog problem

Status
Not open for further replies.

wejos

Member
hello again guys.

I'm having trouble writing the codes to the PIC. The PIC I'm using is 16F84 and the software is PICprog by Martin Penev.

The code came from the tutorial of Mike Cybot's Page. It said this should turn on and off a LED.


;*****Set up the Constants****

STATUS equ 03h ;Address of the STATUS register
TRISA equ 85h ;Address of the tristate register for port A
PORTA equ 05h ;Address of Port A
COUNT1 equ 08h ;First counter for our delay loops
COUNT2 equ 09h ;Second counter for our delay loops

;****Set up the port****

bsf STATUS,5 ;Switch to Bank 1
movlw 00h ;Set the Port A pins
movwf TRISA ;to output.
bcf STATUS,5 ;Switch back to Bank 0

;****Turn the LED on****

Start movlw 02h ;Turn the LED on by first putting
movwf PORTA ;it into the w register and then ;on the port

;****Start of the delay loop 1****

Loop1 decfsz COUNT1,1 ;Subtract 1 from 255
goto Loop1 ;If COUNT is zero, carry on.
decfsz COUNT2,1 ;Subtract 1 from 255
goto Loop1 ;Go back to the start of our loop.
;This delay counts
;255 to zero, 255 times

;****Delay finished, now turn the LED off****

movlw 00h ;Turn the LED off by first putting
movwf PORTA ;it into the w register and then on ;the port

;****Add another delay****

Loop2 decfsz COUNT1,1 ;This second loop keeps the
goto Loop2 ;LED turned off long enough for
decfsz COUNT2,1 ;us to see it turned off
goto Loop2 ;

;****Now go back to the start of the program

goto Start ;go back to Start and turn LED ;on again

;****End of the program****

end ;Needed by some compilers,
;and also just in case we miss
;the goto instruction.



I tried to convert the code to hex using HxD Hex Editor. I tried "16 bit" and "32 bit" format. Both format failed and gave me an error.

**broken link removed**



The Hex looked like this in 32 bit.

:020000020000FC
:100000003B2A2A2A2A2A5365742075702074686551
:1000100020436F6E7374616E74732A2A2A2A200D2E
:100020000A0D0A53544154555320202020202020EB
:10003000202065717520202020202020303368206A
:1000400020202020202020202020202020202020B0
:100050003B41646472657373206F66207468652029
:100060005354415455532072656769737465720D1A
:100070000A545249534120202020202020202020B3
:100080006571752020202020202038356820202010
:1000900020202020202020202020202020203B4124
:1000A000646472657373206F66207468652074726F
:1000B0006973746174652072656769737465722011
:1000C000666F7220706F727420410D0A504F525447
:1000D0004120202020202020202020657175202014
:1000E00020202020203035682020202020202020A3
:1000F0002020202020202020203B41646472657352
:1001000073206F6620506F727420410D0A434F5563
:100110004E54312020202020202020206571752081
:10012000202020202020303868202020202020205F
:10013000202020202020202020203B46697273743C
:1001400020636F756E74657220666F72206F7572B2
:100150002064656C6179206C6F6F70730D0A434F7A
:10016000554E5432202020202020202020657175FB
:10017000202020202020203039682020202020200E
:1001800020202020202020202020203B5365636F4A
:100190006E6420636F756E74657220666F72206F77
:1001A00075722064656C6179206C6F6F7073200DBF
:1001B0000A0D0A3B2A2A2A2A536574207570207476
:1001C000686520706F72742A2A2A2A200D0A200D71
:1001D0000A202020202020202020202020202062F3
:1001E0007366202020202020202053544154555352
:1001F0002C352020202020202020202020203B5390
:10020000776974636820746F2042616E6B20310DD2
:100210000A20202020202020202020202020206DA7
:100220006F766C772020202020203030682020201E
:1002300020202020202020202020202020203B5370
:1002400065742074686520506F7274204120706955
:100250006E730D0A20202020202020202020202026
:1002600020206D6F76776620202020202054524970
:10027000534120202020202020202020202020202A
:10028000203B746F206F75747075742E0D0A2020DA
:100290002020202020202020202020206263662093
:1002A000202020202020205354415455532C352009
:1002B00020202020202020202020203B53776974FC
:1002C0006368206261636B20746F2042616E6B20F3
:1002D00030200D0A0D0A3B2A2A2A2A5475726E20F4
:1002E000746865204C4544206F6E2A2A2A2A200D06
:1002F0000A0D0A53746172742020202020202020CF
:10030000206D6F766C7720202020202030326820EE
:1003100020202020202020202020202020202020DD
:100320003B5475726E20746865204C4544206F6E96
:100330002062792066697273742070757474696EB6
:10034000670D0A202020202020202020202020208F
:10035000206D6F767766202020202020504F525449
:10036000412020202020202020202020202020206C
:100370003B697420696E746F207468652077207201
:100380006567697374657220616E64207468656E58
:10039000202020202020202020202020202020205D
:1003A000202020202020202020202020202020204D
:1003B000202020202020202020202020202020203D
:1003C000202020202020202020202020202020202D
:1003D0002020202020202020202020203B6F6E2065
:1003E00074686520706F7274200D0A0D0A3B2A2A0A
:1003F0002A2A5374617274206F66207468652064C1
:10040000656C6179206C6F6F7020312A2A2A2A204E
:100410000D0A0D0A4C6F6F70312020202020202003
:10042000202064656366737A2020202020434F5586
:100430004E54312C3120202020202020202020202C
:10044000203B537562747261637420312066726F51
:100450006D203235350D0A2020202020202020203C
:100460002020202020676F746F2020202020202053
:100470004C6F6F7031202020202020202020202051
:10048000202020203B496620434F554E542069735D
:10049000207A65726F2C206361727279206F6E2EE4
:1004A0000D0A202020202020202020202020202075
:1004B00064656366737A2020202020434F554E5494
:1004C000322C312020202020202020202020203BE2
:1004D000537562747261637420312066726F6D208F
:1004E0003235350D0A2020202020202020202020F9
:1004F000202020676F746F202020202020204C6F48
:100500006F7031202020202020202020202020203B
:1005100020203B476F206261636B20746F207468FA
:1005200065207374617274206F66206F7572206C21
:100530006F6F702E202020202020202020202020BF
:1005400020202020202020202020202020202020AB
:10055000202020202020202020202020202020209B
:10056000202020202020202020202020202020208B
:1005700020202020202020202020202020200D0AA4
:10058000202020202020202020202020202020206B
:10059000202020202020202020202020202020205B
:1005A000202020202020202020202020203B5468B4
:1005B00069732064656C617920636F756E74732054
:1005C000646F776E2066726F6D20202020202020BF
:1005D000202020202020202020202020202020201B
:1005E000202020202020202020202020202020200B
:1005F00020202020202020202020202020202020FB
:1006000020202020202020202020202020202020EA
:1006100020202020202020202020202020202020DA
:1006200020202020202020202020202020202020CA
:1006300020202020202020200D0A202020202020E3
:1006400020202020202020202020202020202020AA
:10065000202020202020202020202020202020209A
:10066000202020202020203B32353520746F207A36
:1006700065726F2C203235352074696D65730D0AF3
:100680000D0A3B2A2A2A2A44656C61792066696E24
:1006900069736865642C206E6F77207475726E20A4
:1006A000746865204C4544206F66662A2A2A2A20F1
:1006B0000D0A0D0A2020202020202020202020208C
:1006C00020206D6F766C772020202020203030682D
:1006D000202020202020202020202020202020201A
:1006E000203B5475726E20746865204C4544206F21
:1006F00066662062792066697273742070757474FE
:10070000696E670D0A202020202020202020202034
:100710002020206D6F767766202020202020504FEB
:100720005254412020202020202020202020202042
:1007300020203B697420696E746F2074686520778F
:1007400020726567697374657220616E64207468D5
:10075000656E206F6E202020202020202020202069
:100760002020202020202020202020202020202089
:100770002020202020202020202020202020202079
:100780002020202020202020202020202020202069
:1007900020202020202020202020202020203B74EA
:1007A000686520706F7274200D0A0D0A3B2A2A2A90
:1007B0002A41646420616E6F746865722064656CA0
:1007C00061792A2A2A2A200D0A0D0A4C6F6F70328D
:1007D00020202020202020202064656366737A205A
:1007E00020202020434F554E54312C3120202020F2
:1007F00020202020202020203B546869732073652E
:10080000636F6E64206C6F6F70206B656570732012
:100810007468650D0A202020202020202020202020
:10082000202020676F746F202020202020204C6F14
:100830006F70322020202020202020202020202007
:1008400020203B4C4544207475726E6564206F66B1
:1008500066206C6F6E6720656E6F75676820666FC7
:10086000720D0A202020202020202020202020205F
:100870002064656366737A2020202020434F554E04
:1008800054322C3120202020202020202020202005
:100890003B757320746F20736565206974207475CF
:1008A000726E6564206F66660D0A2020202020206D
:1008B0002020202020202020676F746F20202020FF
:1008C0002020204C6F6F70322020202020202020FC
:1008D000202020202020203B200D0A0D0A3B2A2A20
:1008E0002A2A4E6F7720676F206261636B20746FD6
:1008F00020746865207374617274206F6620746858
:10090000652070726F6772616D0D0A0D0A202020DC
:100910002020202020202020202020676F746F209E
:100920002020202020205374617274202020202059
:10093000202020202020202020203B676F20626183
:10094000636B20746F20537461727420616E642035
:100950007475726E204C45442020202020202020D9
:100960002020202020202020202020202020202087
:100970002020202020202020202020202020202077
:100980002020202020202020202020202020202067
:100990002020202020202020202020202020202057
:1009A000202020203B6F6E20616761696E200D0A58
:1009B0000D0A3B2A2A2A2A456E64206F6620746835
:1009C000652070726F6772616D2A2A2A2A200D0ACB
:1009D0000D0A656E64202020202020202020202069
:1009E0002020202020202020202020202020202007
:1009F0002020202020202020202020202020203BDC
:100A00004E656564656420627920736F6D6520634F
:100A10006F6D70696C6572732C0D0A202020202088
:100A200020202020202020202020202020202020C6
:100A300020202020202020202020202020202020B6
:100A400020202020202020203B616E6420616C73D8
:100A50006F206A75737420696E20636173652077F7
:100A600065206D6973732020202020202020202005
:100A70002020202020202020202020202020202076
:100A80002020202020202020202020202020202066
:100A900020202020202020200D0A2020202020207F
:100AA0002020202020202020202020202020202046
:100AB0002020202020202020202020202020202036
:100AC000202020202020203B74686520676F746FF1
:0D0AD00020696E737472756374696F6E2E09
:00000001FF



And like this in 16 bit.

:020000040000FA
:100000003B2A2A2A2A2A5365742075702074686551
:1000100020436F6E7374616E74732A2A2A2A200D2E
:100020000A0D0A53544154555320202020202020EB
:10003000202065717520202020202020303368206A
:1000400020202020202020202020202020202020B0
:100050003B41646472657373206F66207468652029
:100060005354415455532072656769737465720D1A
:100070000A545249534120202020202020202020B3
:100080006571752020202020202038356820202010
:1000900020202020202020202020202020203B4124
:1000A000646472657373206F66207468652074726F
:1000B0006973746174652072656769737465722011
:1000C000666F7220706F727420410D0A504F525447
:1000D0004120202020202020202020657175202014
:1000E00020202020203035682020202020202020A3
:1000F0002020202020202020203B41646472657352
:1001000073206F6620506F727420410D0A434F5563
:100110004E54312020202020202020206571752081
:10012000202020202020303868202020202020205F
:10013000202020202020202020203B46697273743C
:1001400020636F756E74657220666F72206F7572B2
:100150002064656C6179206C6F6F70730D0A434F7A
:10016000554E5432202020202020202020657175FB
:10017000202020202020203039682020202020200E
:1001800020202020202020202020203B5365636F4A
:100190006E6420636F756E74657220666F72206F77
:1001A00075722064656C6179206C6F6F7073200DBF
:1001B0000A0D0A3B2A2A2A2A536574207570207476
:1001C000686520706F72742A2A2A2A200D0A200D71
:1001D0000A202020202020202020202020202062F3
:1001E0007366202020202020202053544154555352
:1001F0002C352020202020202020202020203B5390
:10020000776974636820746F2042616E6B20310DD2
:100210000A20202020202020202020202020206DA7
:100220006F766C772020202020203030682020201E
:1002300020202020202020202020202020203B5370
:1002400065742074686520506F7274204120706955
:100250006E730D0A20202020202020202020202026
:1002600020206D6F76776620202020202054524970
:10027000534120202020202020202020202020202A
:10028000203B746F206F75747075742E0D0A2020DA
:100290002020202020202020202020206263662093
:1002A000202020202020205354415455532C352009
:1002B00020202020202020202020203B53776974FC
:1002C0006368206261636B20746F2042616E6B20F3
:1002D00030200D0A0D0A3B2A2A2A2A5475726E20F4
:1002E000746865204C4544206F6E2A2A2A2A200D06
:1002F0000A0D0A53746172742020202020202020CF
:10030000206D6F766C7720202020202030326820EE
:1003100020202020202020202020202020202020DD
:100320003B5475726E20746865204C4544206F6E96
:100330002062792066697273742070757474696EB6
:10034000670D0A202020202020202020202020208F
:10035000206D6F767766202020202020504F525449
:10036000412020202020202020202020202020206C
:100370003B697420696E746F207468652077207201
:100380006567697374657220616E64207468656E58
:10039000202020202020202020202020202020205D
:1003A000202020202020202020202020202020204D
:1003B000202020202020202020202020202020203D
:1003C000202020202020202020202020202020202D
:1003D0002020202020202020202020203B6F6E2065
:1003E00074686520706F7274200D0A0D0A3B2A2A0A
:1003F0002A2A5374617274206F66207468652064C1
:10040000656C6179206C6F6F7020312A2A2A2A204E
:100410000D0A0D0A4C6F6F70312020202020202003
:10042000202064656366737A2020202020434F5586
:100430004E54312C3120202020202020202020202C
:10044000203B537562747261637420312066726F51
:100450006D203235350D0A2020202020202020203C
:100460002020202020676F746F2020202020202053
:100470004C6F6F7031202020202020202020202051
:10048000202020203B496620434F554E542069735D
:10049000207A65726F2C206361727279206F6E2EE4
:1004A0000D0A202020202020202020202020202075
:1004B00064656366737A2020202020434F554E5494
:1004C000322C312020202020202020202020203BE2
:1004D000537562747261637420312066726F6D208F
:1004E0003235350D0A2020202020202020202020F9
:1004F000202020676F746F202020202020204C6F48
:100500006F7031202020202020202020202020203B
:1005100020203B476F206261636B20746F207468FA
:1005200065207374617274206F66206F7572206C21
:100530006F6F702E202020202020202020202020BF
:1005400020202020202020202020202020202020AB
:10055000202020202020202020202020202020209B
:10056000202020202020202020202020202020208B
:1005700020202020202020202020202020200D0AA4
:10058000202020202020202020202020202020206B
:10059000202020202020202020202020202020205B
:1005A000202020202020202020202020203B5468B4
:1005B00069732064656C617920636F756E74732054
:1005C000646F776E2066726F6D20202020202020BF
:1005D000202020202020202020202020202020201B
:1005E000202020202020202020202020202020200B
:1005F00020202020202020202020202020202020FB
:1006000020202020202020202020202020202020EA
:1006100020202020202020202020202020202020DA
:1006200020202020202020202020202020202020CA
:1006300020202020202020200D0A202020202020E3
:1006400020202020202020202020202020202020AA
:10065000202020202020202020202020202020209A
:10066000202020202020203B32353520746F207A36
:1006700065726F2C203235352074696D65730D0AF3
:100680000D0A3B2A2A2A2A44656C61792066696E24
:1006900069736865642C206E6F77207475726E20A4
:1006A000746865204C4544206F66662A2A2A2A20F1
:1006B0000D0A0D0A2020202020202020202020208C
:1006C00020206D6F766C772020202020203030682D
:1006D000202020202020202020202020202020201A
:1006E000203B5475726E20746865204C4544206F21
:1006F00066662062792066697273742070757474FE
:10070000696E670D0A202020202020202020202034
:100710002020206D6F767766202020202020504FEB
:100720005254412020202020202020202020202042
:1007300020203B697420696E746F2074686520778F
:1007400020726567697374657220616E64207468D5
:10075000656E206F6E202020202020202020202069
:100760002020202020202020202020202020202089
:100770002020202020202020202020202020202079
:100780002020202020202020202020202020202069
:1007900020202020202020202020202020203B74EA
:1007A000686520706F7274200D0A0D0A3B2A2A2A90
:1007B0002A41646420616E6F746865722064656CA0
:1007C00061792A2A2A2A200D0A0D0A4C6F6F70328D
:1007D00020202020202020202064656366737A205A
:1007E00020202020434F554E54312C3120202020F2
:1007F00020202020202020203B546869732073652E
:10080000636F6E64206C6F6F70206B656570732012
:100810007468650D0A202020202020202020202020
:10082000202020676F746F202020202020204C6F14
:100830006F70322020202020202020202020202007
:1008400020203B4C4544207475726E6564206F66B1
:1008500066206C6F6E6720656E6F75676820666FC7
:10086000720D0A202020202020202020202020205F
:100870002064656366737A2020202020434F554E04
:1008800054322C3120202020202020202020202005
:100890003B757320746F20736565206974207475CF
:1008A000726E6564206F66660D0A2020202020206D
:1008B0002020202020202020676F746F20202020FF
:1008C0002020204C6F6F70322020202020202020FC
:1008D000202020202020203B200D0A0D0A3B2A2A20
:1008E0002A2A4E6F7720676F206261636B20746FD6
:1008F00020746865207374617274206F6620746858
:10090000652070726F6772616D0D0A0D0A202020DC
:100910002020202020202020202020676F746F209E
:100920002020202020205374617274202020202059
:10093000202020202020202020203B676F20626183
:10094000636B20746F20537461727420616E642035
:100950007475726E204C45442020202020202020D9
:100960002020202020202020202020202020202087
:100970002020202020202020202020202020202077
:100980002020202020202020202020202020202067
:100990002020202020202020202020202020202057
:1009A000202020203B6F6E20616761696E200D0A58
:1009B0000D0A3B2A2A2A2A456E64206F6620746835
:1009C000652070726F6772616D2A2A2A2A200D0ACB
:1009D0000D0A656E64202020202020202020202069
:1009E0002020202020202020202020202020202007
:1009F0002020202020202020202020202020203BDC
:100A00004E656564656420627920736F6D6520634F
:100A10006F6D70696C6572732C0D0A202020202088
:100A200020202020202020202020202020202020C6
:100A300020202020202020202020202020202020B6
:100A400020202020202020203B616E6420616C73D8
:100A50006F206A75737420696E20636173652077F7
:100A600065206D6973732020202020202020202005
:100A70002020202020202020202020202020202076
:100A80002020202020202020202020202020202066
:100A900020202020202020200D0A2020202020207F
:100AA0002020202020202020202020202020202046
:100AB0002020202020202020202020202020202036
:100AC000202020202020203B74686520676F746FF1
:0D0AD00020696E737472756374696F6E2E09
:00000001FF


The error above appears only when I'm using the Hex that I've converted. If I clicked "program" even when PICprog is empty, it goes all the way to 100% (finished). What am I doing wrong here? Thank you very much.
 
Last edited:
You don't have a 'config' line in the above code.
Also, that tutorial you are using is very old (as is the 16F84). You'd be much better off looking through Nigel's tutorials.
 
hi.
This is the hex file I get, it runs OK in the Oshonsoft Sim
Note: added some info to header.

EDIT: also added END at end of program

Code:
:020000040000FA
:10000000831600308500831202308500880B062895
:10001000890B062800308500880B0C28890B0C28DA
:020020000428B2
:00000001FF
Code:
;*****Set up the Constants****  

;	CONF_WORD = 0x3f31
	list	p=16f84
	#include <p16f84.inc>
	radix	dec
	errorlevel -302, -207

  CONF_WORD = 0x3FF1


STATUS	equ	03h		;Address of the STATUS register
TRISA	equ	85h		;Address of the tristate register for port A
PORTA	equ	05h		;Address of Port A
COUNT1	equ	08h		;First counter for our delay loops
COUNT2	equ	09h		;Second counter for our delay loops

;****Set up the port****  

	bsf	STATUS,5	;Switch to Bank 1
	movlw	00h		;Set the Port A pins
	movwf	TRISA		;to output.
	bcf	STATUS,5	;Switch back to Bank 0

;****Turn the LED on****  

Start	movlw	02h		;Turn the LED on by first putting
	movwf	PORTA		;it into the w register and then ;on the port

;****Start of the delay loop 1****  

Loop1	decfsz	COUNT1,1	;Subtract 1 from 255
	goto	Loop1		;If COUNT is zero, carry on.
	decfsz	COUNT2,1	;Subtract 1 from 255
	goto	Loop1		;Go back to the start of our loop.
;This delay counts  
;255 to zero, 255 times  

;****Delay finished, now turn the LED off****  

	movlw	00h		;Turn the LED off by first putting
	movwf	PORTA		;it into the w register and then on ;the port

;****Add another delay****  

Loop2	decfsz	COUNT1,1	;This second loop keeps the
	goto	Loop2		;LED turned off long enough for
	decfsz	COUNT2,1	;us to see it turned off
	goto	Loop2		;

;****Now go back to the start of the program  

	goto	Start		;go back to Start and turn LED ;on again

 end
;****End of the program****
 
Last edited:
You don't have a 'config' line in the above code.
Also, that tutorial you are using is very old (as is the 16F84). You'd be much better off looking through Nigel's tutorials.

Config line? :confused:

Maybe I missed something in there. I'll recheck his page.

The only PIC available in our area is the 16F84. :eek:

I'll start reading his work.

Thanks man.
 
Config line? :confused:

Maybe I missed something in there. I'll recheck his page.

The only PIC available in our area is the 16F84. :eek:

I'll start reading his work.

Thanks man.


Hi,
Can you paste the hex file from my post into your prommer program and check it out in a 16F84?

Note my last EDIT, added the 'END' directive.

Which assembler program are you using.?
 
Last edited:
ericgibbs thanks also man. the hex says 3FFFs in my PIC programmer. I pasted it in a txt file then renamed the extension to hex. Maybe I should look for other PIC programmers. I saw this winpicprog from the responce of HouseOfWax. Maybe I should try that one also.
 
yes it loads eric thanks man. i used the pic programmer HouseOfWax referred to me. Right now I'm attaching the wires to my serial port. Hope it worked. Many thanks.
 
yes it loads eric thanks man. i used the pic programmer HouseOfWax referred to me. Right now I'm attaching the wires to my serial port. Hope it worked. Many thanks.

hi,
I think I see what you are doing wrong.

Ive downloaded that HxD program, its an Hex Editor, NOT an assembler.!

Did open the program source file with then Hxd then use the EXPORT function.??

If yes, thats why you have a massive file, its converted all of the ascii characters to hex.!!

Goto Microchip Technology Inc. - a Leading Provider of Microcontroller and Analog Semiconductors and download the latest free MPLAB IDE V8.10. Compiler

EDIT: ref your PM, pleased to hear the hex file worked oK.
 
Last edited:
hi,
I think I see what you are doing wrong.

Ive downloaded that HxD program, its an Hex Editor, NOT an assembler.!

Did open the program source file with then Hxd then use the EXPORT function.??

If yes, thats why you have a massive file, its converted all of the ascii characters to hex.!!

Goto Microchip Technology Inc. - a Leading Provider of Microcontroller and Analog Semiconductors and download the latest free MPLAB IDE V8.10. Compiler

EDIT: ref your PM, pleased to hear the hex file worked oK.


LOL :eek: *scratches head*

I appreciate everything. thanks for guiding me...

I get it now. I'll try my best to understand this assembly language.

:eek: assembly
 
i now have the prog eric and got exactly what the hex you posted using it. i think i'm in the right track now thanks to you guys. you are elite.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top