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.

Icd2

Status
Not open for further replies.
This part writes to the TRIS registers, making them all inputs, but it's a really confusing and poor disassembly.

Code:
0013: 1683  BSF    3,5    
0014: 30FF  MOVLW  0FFh
0015: 0085  MOVWF  5
0016: 0086  MOVWF  6
 
Last edited:
hi everyone, problem solved! i connected a wire from the pic's vdd pin to the connector's vdd and it worked. it was kind of a desperate measure, but it worked. now i have another problem hahaha i extracted an hex file from the pic's memory (which i converted to asm, and doing the best to understand how it works) but i don't know where to get information regarding pin configuration. on the hex file i extracted from the pic it doesn't appear...

Didn't you had readed what i wrote before ?

THE ORIGINAL ICD2 NEEDS THE VDD PIN CONNECTED TO TARGET TO POWER THE INTERNAL BUFFER.
Thats why.

Pin configurations are under that same topic on you PIC DATASHEET ! Bit configurations are regarding digital/analogic i/o and things like that, is that what you want ?

Tip:
If you're planning on using ASM use you PIC datasheet PORT initialization examples, wich usually change if the PIC has an ADC or PWM modules on the same ports.

But you are probably refering to BIT CONFIGURATIONS, MPLAB has a dedicated area, wich you should use, until you understaind how to use #pragma config 'BIT' 'STATE'.

I suggest programming in C :p, of course i'm a programmer.

Oh, forgive me my grammar errors!

Another tip:
Disable the Watchdog and the Low Voltage Programming to make the ICD2 work in debug mode. (i guess thats it)

Have fun!
 
bit 5 and 6 would be inputs? any advice to do a better disassembly? I'm kind of lost with this code. i can send you the hex file if you prefer
 
bit 5 and 6 would be inputs? any advice to do a better disassembly? I'm kind of lost with this code. i can send you the hex file if you prefer

Use windows calculator (if you have windows) to convert decimal/hexadecimal numbers to decimal/binary hehehehe

Then on binary:
the 1s on TRIS are inputs, 0s are outputs.

This is easy when you know where to look!
 
bit 5 and 6 would be inputs? any advice to do a better disassembly? I'm kind of lost with this code. i can send you the hex file if you prefer

No, like I said ALL pins will be inputs, 5 and 6 are the numerical values of the TRIS registers in bank 1.

What specific processor is it for?.
 
all pins will be inputs? all pins of the pic? all pins of a certain port?

this pic is mounted on a pcb board along with a lattice fpga device, they control the duty cycle of a motor. from pins 18 and 19 (RC1 and RC2 - PIC16f877 plcc) you get a 50% and a 25% duty cycle respectively (i have checked this with an oscilloscope). the thing is, that i want to understand how the program works because i want to add to more outputs, one with 75% and another with 100% duty cycle.
 
all pins will be inputs? all pins of the pic? all pins of a certain port?

Like L said, ALL pins are set as inputs - they may be altered later on though.

Post the HEX file (as an attachment, click 'Go Advanced'), and I'll disassemble it for you.

this pic is mounted on a pcb board along with a lattice fpga device, they control the duty cycle of a motor. from pins 18 and 19 (RC1 and RC2 - PIC16f877 plcc) you get a 50% and a 25% duty cycle respectively (i have checked this with an oscilloscope). the thing is, that i want to understand how the program works because i want to add to more outputs, one with 75% and another with 100% duty cycle.

RC1 and RC2 are the two PWM output pins, this is a hardware function of the chip, and ONLY on those two pins.

BTW, you don't need a pn for 100% duty cycle, just feed it from 5V.
 
Last edited:
so, the 25% and 50% are a function of the pic device? i know that these are PWM outputs, but then the duty cycles are (according to the program) in no way controlled by the pic? the pic already comes with those %s?
 
so, the 25% and 50% are a function of the pic device? i know that these are PWM outputs, but then the duty cycles are (according to the program) in no way controlled by the pic? the pic already comes with those %s?

No, it's set in the PIC program - which is very small and does nothing except set the two PWM's running and then sits in an endless loop.

Code:
; Generated by WinPicProg 1.95f, (c) Nigel Goodwin June 2006.

            LIST      P=16F877, F=INHX8M
            include "P16F877.inc"
            __CONFIG 0x3B39

; Variable definitions

            ORG     0x0000

            GOTO    Label_0001
            ORG     0x0004
            GOTO    Label_0002
Label_0002  NOP
            RETFIE
Label_0003  BCF     STATUS    , RP0
            CLRF    CCPICON
            CLRF    TMR2
            BSF     STATUS    , RP0
            MOVLW   0x31
            MOVWF   PR2
            BCF     STATUS    , RP0
            MOVLW   0x0C
            MOVWF   CCPRIL
            MOVLW   0x19
            MOVWF   CCPR2L
            CLRF    INTCON
            BSF     STATUS    , RP0
            MOVLW   0xFF
            MOVWF   TRISA
            MOVWF   TRISB
            MOVWF   TRISC
            MOVWF   TRISD
            MOVWF   TRISE
            BCF     TRISC     , 02
            BCF     TRISC     , 01
            CLRF    PIE1
            BCF     STATUS    , RP0
            CLRF    PIR1
            MOVLW   0x2C
            MOVWF   CCPICON
            MOVWF   CCP2CON
            CLRF    T2CON
            BSF     T2CON     , TMR2ON
            RETURN
Label_0004  CLRWDT
            RETURN
Label_0001  CALL    Label_0003
Label_0005  CALL    Label_0004
            GOTO    Label_0005
 
            ORG     0x2000
            DATA    0xFF
            DATA    0x3F
            DATA    0xFF
            DATA    0x3F
 
 

            END
 
so, the program that was in the pic device has nothing to do with the fact that there is a 25% and 50% duty cycle? if i want to generate a 75% i would have to create it separately?
 
Not actually generating it, but it sets up the hardware that does generate it, in the subroutine labelled Label_0003 in my listing.

If you wanted to write software routines to generate two more PWM signals, you could place it at Label_0004 which is the routine called in the main loop.
 
what i mean, is that what "i" control through the pic program is the %duty cycle of the outputs. for example, i could change the 25% for a 75%... but these outputs are one of the pic's functions, what i, as a user decide is the %, right?

(sorry for being so slow to understand...)
 
what i mean, is that what "i" control through the pic program is the %duty cycle of the outputs. for example, i could change the 25% for a 75%... but these outputs are one of the pic's functions, what i, as a user decide is the %, right?

(sorry for being so slow to understand...)

Read the datasheet about the PWM modules, or the mid-range reference manual - or check my PWM 'tutorial' which has a commented example.

But basically you set it with the value in CCPRIL and CCPR2L.
 
hi, a have a few questions regarding the how you disassembled the code

Code:
; Generated by WinPicProg 1.95f, (c) Nigel Goodwin June 2006.

            LIST      P=16F877, F=INHX8M
            include "P16F877.inc"
            __CONFIG 0x3B39

; Variable definitions

            ORG     0x0000

            GOTO    Label_0001
            ORG     0x0004
            GOTO    Label_0002
Label_0002  NOP
            RETFIE
Label_0003  BCF     STATUS    , RP0
            CLRF    CCPICON
            CLRF    TMR2
            BSF     STATUS    , RP0
            MOVLW   0x31
            MOVWF   PR2                      ; why PR2? 0x12 is T2CON right?
            BCF     STATUS    , RP0
            MOVLW   0x0C
            MOVWF   CCPRIL
            MOVLW   0x19
            MOVWF   CCPR2L
            CLRF    INTCON
            BSF     STATUS    , RP0
            MOVLW   0xFF
            MOVWF   TRISA
            MOVWF   TRISB
            MOVWF   TRISC
            MOVWF   TRISD
            MOVWF   TRISE
            BCF     TRISC     , 02
            BCF     TRISC     , 01
            CLRF    PIE1                                       ;why are these two lines 
            BCF     STATUS    , RP0                      
            CLRF    PIR1                                       ; different if they are both
                                                                             CLRF   0xC
            MOVLW   0x2C
            MOVWF   CCPICON
            MOVWF   CCP2CON
            CLRF    T2CON
            BSF     T2CON     , TMR2ON
            RETURN
Label_0004  CLRWDT
            RETURN
Label_0001  CALL    Label_0003
Label_0005  CALL    Label_0004
            GOTO    Label_0005
 
            ORG     0x2000
            DATA    0xFF
            DATA    0x3F
            DATA    0xFF
            DATA    0x3F
 
 

            END
 
Status
Not open for further replies.

Latest threads

Back
Top