Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] i CAN'T BELIEVE IT THIS ACTUALLY WORKS !

Status
Not open for further replies.

techristian

Member level 1
Joined
Apr 3, 2013
Messages
41
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Windsor, Ontario
Activity points
1,611
I still haven't figured out the banking and TRIS command, but somehow the program listed below actually works ! I will post a video to youtube of my first running PIC project but I'm not sure if I can put links up here.

Nevertheless , it is kludgy but the code is entirely mine. It counts in HEX from 0 to 15 on a SINGLE 7 segment display.
#include <p16f1784.inc>

;CONFIG1
; __config 0x3FE4
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON
; CONFIG2
; __config 0x3FFF
__CONFIG _CONFIG2, _WRT_OFF & _VCAPEN_OFF & _PLLEN_ON & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_ON

delay equ 0x3e
BIGdelay equ 0x3f


org 0x0000
goto start

org 0x004
goto dummyINT

start movlw b'00000000' ;MOVE ZERO TO ACC "W"orking register







BANKSEL 1
TRIS 7

movlw B'00000000' ;


BANKSEL 0
loop
movlw b'01110111' ;ZERO
movwf PORTC
call PAUSE

movlw b'01000001' ;one
movwf PORTC
call PAUSE

movlw b'00111011' ;TWO
movwf PORTC
call PAUSE

movlw b'01101011' ;three
movwf PORTC
call PAUSE

movlw b'01001101' ;4
movwf PORTC
call PAUSE

movlw b'01101110' ;5
movwf PORTC
call PAUSE
movlw b'01111110' ;6
movwf PORTC
call PAUSE
movlw b'01000011' ;7
movwf PORTC
call PAUSE
movlw b'01111111' ;EIGHT
movwf PORTC
call PAUSE
movlw b'01001111' ;9
movwf PORTC
call PAUSE
movlw b'01011111' ;A
movwf PORTC
call PAUSE
movlw b'01111100' ;B
movwf PORTC
call PAUSE
movlw b'00110110' ;C
movwf PORTC
call PAUSE
movlw b'01111001' ;D
movwf PORTC
call PAUSE
movlw b'00111110' ;E
movwf PORTC
call PAUSE
movlw b'00011110' ;F
movwf PORTC
call PAUSE
;loop forever
goto loop

PAUSE movlw 0xC0
MOVWF BIGdelay
D250 movlw 0xFE
movwf delay
l250 decfsz delay,f
goto l250
DECFSZ BIGdelay,f
GOTO D250
return





dummyINT retfie

end

To answer the question "What was wrong before?"

1) Still not sure about the TRIS implementation but the above code works. Not sure about the banking either!
2) One big thing is the PAUSE routine that I wrote. The original delay was way too short and the LEDS weren't even lighting up.

So if I count clock cycles in my PAUSE subroutine I might actually figure out my CLOCK FREQUENCY !

DAN
 
Last edited:

It is unsettling to think how often we fix something and we don't know just how we did it.

We want to know, because otherwise it means the same problem could show up in another project.
 

It is unsettling to think how often we fix something and we don't know just how we did it.

We want to know, because otherwise it means the same problem could show up in another project.
Yes but seeing it working gives strength and morale to go on. It also gives a basis to try different things around the working way and makes easier to understand and shortens the path to the target. But enough time should be spent on it. Otherways the upcoming surprises may result to give-up ;)
 

Code:
start movlw b'00000000'	 ;MOVE ZERO TO ACC "W"orking register
BANKSEL 1
TRIS 7
BANK1 is where TRIS register. BANKSEL 1 command is selecting BANK1. BANKSEL is a command which automatically select the page where register is. . TRIS 7 moves value of W to TRIS 7. It sets portC direction, making them all output.So how can you say that,
I still haven't figured out the banking and TRIS command
The next line is unnecssary. It is repetition because W is already zero. Secondly you are changing it to
movlw b'01110111'
After that whole program is executed in BANK0 changing portC bits as required eiher setting high or low..
 

The next line is unnecssary. It is repetition because W is already zero. Secondly you are changing it to
movlw b'01110111'

This line of code is actually the BIT PATTERN required to display the number ZERO on my 7 segment display. Yes it is required. The next one is one, then two,etc.

I have since found a better way to implement this using BRW and tables.

Dan
 

Code:
start movlw b'00000000'	 ;MOVE ZERO TO ACC "W"orking register






BANKSEL 1
TRIS 7

movlw B'00000000' ; This is repetition I was taking about
Here, in First line W is cleared.
start movlw b'00000000' ;MOVE ZERO TO ACC "W"orking register
Then again it is repeated althoug W register is not changed between lines.
movlw B'00000000' ; This is repetition I was taking about
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top