flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > Binary Clock using pic16f88

Author
Thread Post new topic Reply to topic
Carl03



Joined: 27 Oct 2012
Posts: 3
Location: Cape Town
Carl03
Hi, I am new to the forum and I am in desperate need of help.
I built the hardware to my binary clock I am making, my problem the code. I am new to the programming world and i am using MPLab to write the code, asm code. I would like to know if anyone can please help me in writing this code?
I am using a 3x6 LED matrix display
one row for hours, minutes and seconds with 6 LEDs in each row
the hours is connected to RA0
the minutes to RA1
the seconds to RA2
starting from right to left each LED in the row is connected to RB0(far right) up until RB5(far left)
i also have to buttons for setting the time connected to RA3(hours set) and RA4(minutes set) when pressed should clear seconds[img][/img]

Any help would be welcomed.
Thanx in advance


Description: Board Layout
Filesize: 317.41 KB
Viewed: 6053 Time(s)

IMG-20121027-00055.jpg


Post 27 Oct 2012, 12:19
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17492
Location: In your JS exploiting you and your system
revolution
Is this a homework assignment?
Post 28 Oct 2012, 04:59
View user's profile Send private message Visit poster's website Reply with quote
Carl03



Joined: 27 Oct 2012
Posts: 3
Location: Cape Town
Carl03
It's a project I'm working on for University yes. I am struggling with how to start the code and I can't wait to get it working so I can see it in action.
Post 28 Oct 2012, 05:10
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17492
Location: In your JS exploiting you and your system
revolution
I suggest that the first thing you need to figure out is the timing. Get an interrupt routine working based upon a fixed period (one second perhaps) and have it do something simple like toggle an LED on/off each interrupt. Then up the interrupt rate to do a scan across the three sets of LEDs until they look like they are on but dimmer. Once that is working and debugged then you can add the actual RTC counting code. And then later add the button detection code which could be handled by the main loop.
Post 28 Oct 2012, 07:11
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
you first need a real timing to trigger the interrupt using a quartz.

do you have source code to start? cause if you didn't started to code, what can we do for you?

the full diagram can help too to code something.
Post 29 Oct 2012, 04:14
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1607
Location: Ukraine
shoorick
i'm not experienced on PICs, but seems it is a similar project:
http://www.obelisk.demon.co.uk/electronics/clock.html
Post 29 Oct 2012, 07:45
View user's profile Send private message Visit poster's website Reply with quote
Carl03



Joined: 27 Oct 2012
Posts: 3
Location: Cape Town
Carl03
I've completed everything and works fine. My buttons are to set the hours and minutes. My hours set button is connected to RA3 and minutes set button is connected to RA4 and this also resets the seconds. I've written a bit of code but when I start the program, it scrolls through the hours fast (very fast) until I press the hours set button does the same with minutes
Code:
check_delay:
      incf    debounce, f
 movf    debounce, w
 sublw   .255
        skpweq
      goto    check_delay
 clrf    debounce
    goto    check_buttons

check_buttons:
     movf    PORTA, w
    movwf   buttons 
    btfss   buttons,4
   goto    check_end
   btfss   buttons, 3
  btfss   buttons, 4
  goto    set_hours
   goto    set_min

set_hours:
       btfss   buttons, 3
  goto    check_end
   incf    hour, f
     movf    hour, w
     sublw   d'24'
     skpweq
      goto    show_hour
   clrf    hour
show_hour:
      movf    hour, w
     movwf   hour
        bsf             T2CON, TMR2ON           
    return

set_min:
  incf    min, f
      movf    min, w
      sublw   d'60'
     skpweq
      goto    show_min
    clrf    min     
show_min:
   movf    min, w
      movwf   min

check_end:
   bsf             T2CON, TMR2ON
       return    


Description: This is my schematic
Download
Filename: Schematic.pdf
Filesize: 116.46 KB
Downloaded: 390 Time(s)

Post 21 Nov 2012, 11:39
View user's profile Send private message Send e-mail Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade
Based on your circuit diagram, your buttons are active-low, and therefore the associated PORTA bit would be set if the button is not pressed, and clear if the button is currently being pressed.

Your check_buttons function looks.. strange. I dont know why you're trying to do an early-exit based on the value of RA4 - then checking whether RA3 and RA4 are pressed.

Why not just use something like:

Code:
check_buttons:
        movf    PORTA,w
     movwf   buttons
     btfss   buttons,4
   goto    set_min
     btfss   buttons,3
   goto    set_hours
   goto    check_end    


FYI: You dont need to read PORTA into a variable first, you could simply use PORTA directly in all your btfss functions. It would save you quite a few instructions, as well as a byte in RAM.
Post 26 Nov 2012, 11:41
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.