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.

pic16f628A 74hc595 code problems.

Status
Not open for further replies.

lurkepus

Member
Hi, i have been playing around with a 16F628A and a 595 chip but i have som problems and i wonder if the problem is hardware or software related

Code:
;*******************************************************
;        74HC595 parallel to serial routine .
;
;        Author Stig Larsen
;
;        Pic16F628A
;
;        januar 2015
;
;*********************************************************

list      p=16f628A           ; list directive to define processor
    #include <p16f628a.inc>       ; processor specific variable definitions

    errorlevel  -302              ; suppress message 302 from list file

    __CONFIG _FOSC_INTOSCCLK & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _BOREN_ON & _LVP_ON & _CPD_OFF & _CP_OFF

cblock  0x20
data1
test
RXT
d1
d2
d3                    ;
;VARF
endc
;***** VARIABLE DEFINITIONS
;data1   EQU     0x70        ;
data2   EQU     0x71        ;
;RXT     EQU     0x72
VARF    EQU     0X73



;**********************************************************************
    ORG     0x000             ; processor reset vector
    goto    main              ; go to beginning of program




;
;  defines
;

;*******************HC595 pins****************************************
; Pic pin 17 (DS)to pin 14
; Pic pin 18 (SH)to pin 11
; Pic pin 1  (ST)to pin 12
; 595 Pin 10 16 to +
; 595 Pin  8 13  to  Gnd
;********************************************************************
#define PIN_DS PORTA,0 ; DS (serial data in)
#define PIN_SH PORTA,1 ; SH_CP(shift)
#define PIN_ST PORTA,2 ; ST_CP (latch)
;****************************************************************
;        Port init
;
;****************************************************************
main
CLRF PORTA
MOVLW 0x07
MOVWF CMCON
BCF STATUS, RP1
BSF STATUS, RP0 ;Select Bank1
MOVLW b'00001000'
MOVWF TRISA
MOVLW 0xf0
MOVWF TRISB
BANKSEL PORTA


;************hc595 routine test **************
_595
  movlW .8
  movwf RXT
  ;clrf data1
  movlw b'11110000'
  movwf data1
  bcf PIN_ST
d0
        btfsc     data1,7
        bsf   PIN_DS
        btfss   data1,7
        bcf     PIN_DS
        bsf     PIN_SH
        nop
        bcf     PIN_SH
     rlf data1

  DECFSZ RXT,F
  goto d0
  bsf PIN_ST
  nop
  bcf PIN_ST
call Delay
  goto _595
Delay
            ;3999994 cycles
    movlw    0x23
    movwf    d1
    movlw    0xB9
    movwf    d2
    movlw    0x09
    movwf    d3
Delay_0
    decfsz    d1, f
    goto    $+2
    decfsz    d2, f
    goto    $+2
    decfsz    d3, f
    goto    Delay_0

            ;2 cycles
    goto    $+1

            ;4 cycles (including call)
    return
  end
 
I checked this out.. MPASMWIN complained about the config but after fixing it it runs okay

The delay is extremely long ... 16 Seconds but like I said... It works.. If there is an issue it must be hardware related..
 
I checked this out.. MPASMWIN complained about the config but after fixing it it runs okay

The delay is extremely long ... 16 Seconds but like I said... It works.. If there is an issue it must be hardware related..
i'm using MplabX v2.3 and it's not complaining and the simulation works ..

maybe the reason is that i'm not using pull up/down resistors on the 595 pin 10 and 13?
 
Last edited:
you have not said what problems ...595 .... MR needs to pull up to Vcc , either directly, I prefer to use 10k and OE needs to go directly to gnd to enable outputs.
 
this are the pins i have used but with no pul up resistor
Pic pin 17 (DS)to pin 14
; Pic pin 18 (SH)to pin 11
; Pic pin 1 (ST)to pin 12
; 595 Pin 10 16 to +
; 595 Pin 8 13 to Gnd
 
This did strike me as unusual....

I use Proteus to simulate..... When using the internal OSC the simulator give a warning to say that the OSC value is determined in software.... Thus it should run at 4Mhz.... Your code doesn't.... It runs on the external settings.. I have checked your config bits and they seem to be right....

Can you try this for me..

__config 0x3D18

See if it runs differently???
 
This did strike me as unusual....

I use Proteus to simulate..... When using the internal OSC the simulator give a warning to say that the OSC value is determined in software.... Thus it should run at 4Mhz.... Your code doesn't.... It runs on the external settings.. I have checked your config bits and they seem to be right....

Can you try this for me..

__config 0x3D18

See if it runs differently???

I did try to simulate the code and it worked butin circuit it didn't so my guess is that the pic might have been fried so i'm going to change both of em as soon as i have the time :)
Wouldn't using a 16F88 with SPI do this in hardware?
https://www.microchip.com/forums/m724235.aspx
It probably would but i don't have any 16F88 so i use the F628A :)
 
I finally got it working :). I changed the config part and started the breadboarding from scratch and found that the pic chip was fried and when i changed it and rewired the breadboard it was working like a charm :)

Next step is to add a 74hc165 chip and some buttons and sensors :)

Did you use 0.1µF decoupling capacitors on both I.C.s?

PS any interest in writing this is C?

I didn't use any caps but it still works :). I might look in to C later but for now i will use assembly :)
 
If you don't have bypass caps, all sorts of mysterious, non-reproducible problems can appear. They are highly recommended and aren't optional.
 
i have added the decoupling caps but i didn't notice any difference on the breadboard , anyway i will add it to the pcb i'm designing :)
 
Status
Not open for further replies.

Latest threads

Back
Top