problem with the pic 16f684

Thread Starter

Anas0801

Joined Jan 6, 2021
13
hi people,I really need some help with this. I have to create a count-up that goes from 0 to 59 with a 200msec delay between the units, but I can't find anything on the internet that could help me, so I am asking to you. The deadline is tomorrow, if you could help me do it i would really appreciate it. I have to do it in assembly for the pic 16f684 and connect it to 2 7segments' display.thanks, and sorry for the bad language, i am from italy :) .
 

Attachments

ericgibbs

Joined Jan 29, 2010
11,551
hi anas,
Welcome to AAC.

As this is Homework please post your best attempt at answering the question, we can then help you.

Your images are not visible.:(
E
 

Thread Starter

Anas0801

Joined Jan 6, 2021
13
hi anas,
Welcome to AAC.

As this is Homework please post your best attempt at answering the question, we can then help you.

Your images are not visible.:(
E
well, i didn't ment to sent images, but i guess my computer does what it wants haha. Btw this is a project that i have to finish for tomorrow, i think it will be simple for you, but for me, hehe, i don't know anything about the pic but i was reading a lot of datasheet about the pic 16f684 and it's too compless to understand it. The project is to create a project with 2 switches and 2 7segments display. One switch is to add 1 on the display, and the other one is to decrease 1 on the display, with an update every 200msec. Thanks
 

Thread Starter

Anas0801

Joined Jan 6, 2021
13
well, i didn't ment to sent images, but i guess my computer does what it wants haha. Btw this is a project that i have to finish for tomorrow, i think it will be simple for you, but for me, hehe, i don't know anything about the pic but i was reading a lot of datasheet about the pic 16f684 and it's too compless to understand it. The project is to create a project with 2 switches and 2 7segments display. One switch is to add 1 on the display, and the other one is to decrease 1 on the display, with an update every 200msec. Thanks

I just realiazed, one of the switch make the pic count up and the other one is for the count down.
 

BobTPH

Joined Jun 5, 2013
2,721
One has to wonder how you got into the state of having to do a program for a PIC with 1 day to go and no knowledge of the PIC. When was this assignment given? Has the PIC been covered in class? Were you supposed to learn it on your own?

Bob
 

Thread Starter

Anas0801

Joined Jan 6, 2021
13
One has to wonder how you got into the state of having to do a program for a PIC with 1 day to go and no knowledge of the PIC. When was this assignment given? Has the PIC been covered in class? Were you supposed to learn it on your own?

Bob
well, that's embarrassing, I had like 2 weeks to do this, but I left it on last because I was studying for other lessons. And I thought like I could do it by finding some examples on the internet or learn it some days before, but damn, time passes so much faster than I thought and here I am, asking for some help to do this. We had a little preparation but not much to start our programming project. My last project was like turn on and turn off a led with a switch
 

jpanhalt

Joined Jan 18, 2008
10,913
Is that even possible? The 2 pins in right can read the 2 switches or no?
A
Probably not. They are floating. Thus, their state is not determined. Then you pull them high. How do they get low again.

As for not knowing anything about switches, I suspect that was covered either more than 2 weeks ago or in another class. Since you don't know anything about switches, PIC MCU's, coding, and it's due tomorrow, when is the drop/fail date?
 

sagor

Joined Mar 10, 2019
318
Not clear if you check the inputs every 200ms or not, or is it just update the LED display that often (would make a flickering display). Hint, put about 10k pull down resistors on RC4 and RC5 to prevent them from "floating" when not switched.
Set up a 200ms timer and loop in the program checking the timer flag. If the homework requires an interrupt routine, then it gets a bit more complicated - you have to enable interrupts and use the timer to trigger it.
Verify what clock frequency your code is running at. Default is 4Mhz,. even though it has an internal 8Mhz oscillator
 

djsfantasi

Joined Apr 11, 2010
7,187
well, that's embarrassing, I had like 2 weeks to do this, but I left it on last because I was studying for other lessons. And I thought like I could do it by finding some examples on the internet or learn it some days before, but damn, time passes so much faster than I thought and here I am, asking for some help to do this. We had a little preparation but not much to start our programming project. My last project was like turn on and turn off a led with a switch
I know how tempting it is to “find examples on the web”. But if that’s all there is to coding, to MCUs, to electronics, there would be no schools to teach that stuff.

IMHO, you have wasted the time necessary to complete your assignment. Even if someone were to give you the answer, it’s doubtful that you’d have the understanding to make it work in the time left. Ethical considerations aside, your best bet is to steal a classmates project (Warning: I am NOT recommending this solution).
 

Thread Starter

Anas0801

Joined Jan 6, 2021
13
I know how tempting it is to “find examples on the web”. But if that’s all there is to coding, to MCUs, to electronics, there would be no schools to teach that stuff.

IMHO, you have wasted the time necessary to complete your assignment. Even if someone were to give you the answer, it’s doubtful that you’d have the understanding to make it work in the time left. Ethical considerations aside, your best bet is to steal a classmates project (Warning: I am NOT recommending this solution).
well, that's the problem. Neither my class couldn't did it :D. I am only asking you guys what are the steps that should I take, without giving me the solution of course
 

Thread Starter

Anas0801

Joined Jan 6, 2021
13
it's 20.21 from Italy and the deadline is tomorrow morning at 8 o'clock, so I have like 11 hours to work on it
 

Thread Starter

Anas0801

Joined Jan 6, 2021
13
ok, so. the photo "3" is the circuit, the "4" is the decoder, and the "5" is telling me wich pin should i turn on for outputting a number in the display. But i don't know how to turn them on, i just tried with :
"bsf D5_ON"
but i defined it before like:
"#define D5_ON B'00000100' ; D5 LED"
 

Attachments

jpanhalt

Joined Jan 18, 2008
10,913
You need to post your entire code and use code tags like this: [code] <insert code>[/code]

Your last line doesn't make sense. It defines D5_ON as 4

You probably need a header (simulators vary), and an include for "PIC16F684.inc". For the simulator I use, it would be written like this:
Code:
    list        p=16f684      ; list directive to define processor
    #include    <p16f684.inc> ; processor specific variable definitions
 

Thread Starter

Anas0801

Joined Jan 6, 2021
13
never mind, one of my teamates just finished and send it to me, but it's more simple than what i wanted to do
Don't mind the italian comments, even if they aren't that much

Code:
;DIRETTIVE
    list p=16f684 
    #include <p16f684.inc>
    errorlevel -302
    __CONFIG     _CP_OFF &_CPD_OFF &_MCLRE_OFF &_WDT_OFF &_PWRTE_ON  &_INTRC_OSC_NOCLKOUT
;DEFINIZIONE COSTANTI E VARIABILI
    cblock 0x20
CONTATORE ; contatore per ritardo
UNITA; variabile di conteggio
DECINE
    endc
;INIZIALIZZAZIONE
    org 0x000
    goto Initialize
    org 0x005 
Initialize
    bsf STATUS, RP0 ; banco 1
    movlw B'10000001' 
    movwf OPTION_REG 
    clrf ANSEL ; I/O digitale
    movlw 0x00 
    movwf TRISC 
    movlw 0x00
    movwf TRISA
    bcf STATUS, RP0
    movlw .0
    movwf UNITA
    movlw .0 
    movwf DECINE
;PROGRAMMA
Inizio
    movfw UNITA
    movwf PORTC 
    movfw DECINE
    movwf PORTA
     call ritardo
    incf UNITA,1
     movlw .10
    xorwf UNITA,0
    btfss STATUS,Z 
     goto controllodecine
     clrf UNITA 
     incf DECINE,1 
controllodecine
     movlw .6 
     xorwf DECINE,0
     btfsc STATUS,Z
     clrf DECINE
     goto Inizio 
;SOTTOPROGRAMMA
ritardo
    movlw .195 
    movwf CONTATORE
loopesterno
    clrf TMR0 
    bcf INTCON,T0IF
loopinterno
    btfss INTCON,T0IF
    goto loopinterno
    incfsz CONTATORE,1 
    goto loopesterno
    return
    end
 

Attachments

jpanhalt

Joined Jan 18, 2008
10,913
Probably, a great learning experience for your teammate. You?

EDIT: If I were your professor, I would ask where you found this instruction: movfw
I know it works, but it is not in the datasheet for the 16F684.
 
Last edited:
Top