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.

Request for hep!!!

Status
Not open for further replies.

Pook

New Member
Hello,

Im sure as a new member there is a protocol im not following, I have read the sticky FAQ and a large number of posts about people fantastic projects.

Which makes it all the much more pathetic that i cant get my simple atempt to work.

The code should be a simple counter - the units and tens being desplayed on 1 LED each - tens are represented by blue LED's and units by white.

The only problem is it dosent work at all... hmm

Could someone possibly have a look at the code bellow and give me some pointers - both on getting it to work & on any style or best practice tips

Thanks very much

Piers


*************************************************************
; HEADER628C.ASM for 16F628. Using internal 37kHz RC
; PortA bits 0 to 7 are inputs
; PortsB bits 0 to 7 are outputs
; Prescaler /32
;***********************************************************************************

; EQUATES SECTION

TMR0 EQU 1 ;means TMR0 is file 1.
OPTION_R EQU 1 ;the OPTION register is file 1
PORTA EQU 5 ;means PORTA is file 5.
PORTB EQU 6 ;means PORTB is file 6.
TRISA EQU 5 ;TRISA (the PORTA I/O selection) is file 5
TRISB EQU 6 ;TRISB (the PORTB I/O selection) is file 86H
STATUS EQU 3 ;means STATUS is file 3.
ZEROBIT EQU 2 ;means ZEROBIT is bit 2.
CARRY EQU 0
EEADR EQU 1BH
EEDATA EQU 1AH
EECON1 EQU 1CH
EECON2 EQU 1DH
RD EQU 0
WR EQU 1
WREN EQU 2
PCON EQU 0EH
COUNT EQU 20H ;COUNT is file 20H, a register to count events.

PC EQU 2
TIMEU EQU 21H
TIMET EQU 22H
TIMEPA EQU 23H
TIMEPB EQU 24H
TEMP EQU 25H
TIMETEMP EQU 26H


;*********************************************************

LIST P=16F628 ; we are using the 16F628.
ORG 0 ;the start address in memory is 0
GOTO START ; goto start!

;*********************************************************

;SUBROUTINE SECTION.

;1 second delay.

DELAY1 MOVLW 10
MOVWF COUNT
LOOPB CALL DELAYP1
DECFSZ COUNT
GOTO LOOPB
RETLW 0

; 0.1 second delay.

DELAYP1 CLRF TMR0
LOOPA MOVF TMR0,W
SUBLW .29
BTFSS STATUS,ZEROBIT
GOTO LOOPA
RETLW 0


;UNITS SUB

UNITS INCF TIMEU
MOVF TIMEU,W
SUBLW .10
BTFSC STATUS,ZEROBIT
CALL TENS ;CALL TENS SUB IF TIMEU = 10
RETLW 0

;TENS SUB

TENS INCF TIMET
MOVF TIMET,W
SUBLW .6
BTFSC STATUS,ZEROBIT
CLRF TIMET ;CLEAR TIMET IF IS 6
CLRF TIMEU
RETLW 0



UNITTABLE ADDWF PC
RETLW B'00000000' ;0
RETLW B'00000001' ;1
RETLW B'00001001' ;2
RETLW B'00001011' ;3
RETLW B'01001011' ;4
RETLW B'01001111' ;5
RETLW B'01011111' ;6
RETLW B'11011111' ;7
RETLW B'11111111' ;8
MOVLW B'00000001' ;9 SET PORTA
MOVWF TIMEPA
RETLW B'11111111'

;TENS DISPLAY TABLE

TENSTABLE ADDWF PC
RETLW B'00000000' ;0
RETLW B'00000010' ;1
RETLW B'00000110' ;2
RETLW B'01000110' ;3
RETLW B'01001110' ;4
RETLW B'11001110' ;5

;CONVERT UNITS TO DISPLAY

CONVUNITS CLRF TIMEPA
MOVF TIMEU,W
CALL UNITTABLE
MOVWF TIMEPB
RETLW 0

;CONVERT TENS TO DISPLAY

CONVTENS MOVF TIMET,W
CALL TENSTABLE
IORWF TIMEPA
RETLW 0

;DISPLAY

DISPLAY MOVF TIMEPB,W
MOVWF PORTB
MOVF TIMEPA,W
MOVWF PORTA
RETLW 0

;*********************************************************

;CONFIGURATION SECTION

START BSF STATUS,5 ;Turns to Bank1.
MOVLW B'00000000' ;PORTA are OUTPUT
MOVWF TRISA

MOVLW B'00000000' ;ddd
MOVWF TRISB ;PORTB is OUTPUT

MOVLW B'00000100' ;Prescaler is /32
MOVWF OPTION_R ;TIMER is 1/32 secs.
CLRF PCON
BCF STATUS,5 ;Return to Bank0.
CLRF PORTA ;Clears PortA.
CLRF PORTB ;Clears PortB.
MOVLW 7
MOVWF 1FH

;*********************************************************

;Program starts now.

BEGIN CLRF TEMP
TEST CALL UNITS
CALL CONVUNITS
CALL CONVTENS
CALL DISPLAY
CALL DELAY1
GOTO TEST

END ;END
 
The first thing that stands out is the lack of a CONFIG instruction.

A config line that should work is
Code:
             __config     0x3d10

This sets up the chip to use the internal 4meg oscillator and the various pin configurations. Have a look at the datasheet under section 14 for a fuller explanation.

The other thing you should do is to include the definition file. This will define all the special function registers like TMR0.
At the top of your code you should have:-
Code:
        processor     16f628
#define     __16f628
        include    "p16f628.inc"

HTH

Mike.
edit - typo.
 
Pook said:
Im sure as a new member there is a protocol im not following, I have read the sticky FAQ and a large number of posts about people fantastic projects.

In addition to Pommie's good advice, I would like to add:

1. In pasting code to the forum, you can surround your code using the pair of "[ code ]" attribute and the code will then appear just as they do in your editor for easy viewing.

2. You said the program did not work. What did it show? All LEDs off, some on some off or changing randomly. All these are pointers to debugging.

3. When the program does not work, do it in steps. Do not debug the whole program. First try to light half of the LEDs on a port to see whether you can do just that, follows with the GOTO instruction to loop forever. Gradually adding other parts to your program bit by bit to build it up.
 
eblc1388 said:
3. When the program does not work, do it in steps. Do not debug the whole program. First try to light half of the LEDs on a port to see whether you can do just that, follows with the GOTO instruction to loop forever. Gradually adding other parts to your program bit by bit to build it up.

All sound advice - going a little further on that theme, don't try and write all your program in one go, build it up a part at a time, and confirm each part is fully functional before continuing.

In your particular case I would suggest doing the 'display' section first, use a simple incrementing counter to feed it varying values.
 
Status
Not open for further replies.

Latest threads

Back
Top