Chess clock

Go To Last Post
89 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

hello everyone, you will notice that the old text that came out here was eliminated in order to be able to put together something more decent and more specified to make it easier for you to help and that you can observe the progress of the project as it happens.

 

overall concept: The idea is to make a chess clock that presents a time of 5 minutes for each player, when a player presses the button on his side, the time of the other player of 5 minutes starts to run slowly until it reaches 0, if the player who has time running press the button on your side will make your opponent's time run, the idea of ​​this is that players don't take forever to make their moves

 

a little video that show what are how a chess clock  works https://www.youtube.com/watch?v=...

 

conditions:

the project has specific conditions to be carried out, since it is a school project

 

arduino is forbidden for the final project, since it must be done on a custom board, but it can be used to test things, as long as the bascom language is used and not the language that is commonly used in arduino

which brings us to the next point, the programming language that is being used is bascom, and the bascom avr compiler is being used I attach a link to the bascom avr page so that you can locate which one it is

https://www.mcselec.com/index.ph... are working with the demo version that allows a code of up to 4kb

 

 

 

the time I have for the completion of the work is until November of this year, practically at the end of the course

 

 

 

specs:

In this section I will present the materials that I count for the project, such as the display chip etc, for the simulations I often use generic materials,

 

the head of the project and the most important component is the microchip -ATmega328p 

 

this component arose by recommendation from this forum, it is currently the one we are working with and trying to understand, it is quite good because here in Argentina it is not very expensive and it would allow me to do what I need the component in question is the max7219 that would be used to control the 7-segment led screens.

 

for the screen as it is mentioned above and it is a simple deduction when seeing the text above, the idea is to use two 7-segment led screens of four digits each, you are being a common cathode

 

to practice we have a common protoboard that is used to test without the need to solder anything

 

I have thought about the idea of ​​using an rtc although I haven't tried it or read much about it yet, we consider it necessary for the project because the micro with the amount of functions and things that are going to be asked of it will be unable to count 5 minutes in a real way, that's why the rtc (real time clock)

 

for the battery we didnt decide what to use to power it up, probably batterys or a rechargable battery from cellphones

 

I am going to attach photos of the components and show a code which we are trying to edit but we are still a bit lost in its operation 

 

An individual from the forum sent us a pdf that explained the operation of the max7219 and showed an example code that allowed reading through the adc a value in volts that passes through a potentiometer, a kind of multimeter up to 5v

 

 

now we are trying to put 2 buttons to activate one counter and one activate the other, but when i push one the other will stop 

$crystal = 8000000

$regfile = "m328Pdef.dat"

$hwstack = 40
$swstack = 32
$framesize = 52

Dim Digitos(8) As Byte                                      'Se dimensiona variable array con 8 elementos tipo byte
Dim Numero As Word
Dim I As Byte

Dim D1 As Byte
Dim D2 As Byte
Dim D3 As Byte
Dim D4 As Byte
Dim D5 As Byte
Dim D6 As Byte
Dim D7 As Byte
Dim D8 As Byte                                              'dimension variable byte para el valor de cada dígito

D1 = 0
D2 = 0
D3 = 0
D4 = 0

D5 = 9
D6 = 9
D7 = 9
D8 = 9

Const Reg_decode_mode = &B1111100111111111
Const Reg_scan_limit = &B1111101111111111
Const Reg_intensity = &B1111101011111111
Const Reg_shutdown = &B1111110011111111

Config Portc.0 = Output                                     'Configuración puerto C como salida
Config Portc.1 = Output
Config Portc.2 = Output

Max_data Alias Portc.0
Max_load Alias Portc.1
Max_clock Alias Portc.2

Max_load = 1
Numero = Reg_shutdown
Gosub Sai_max
Numero = Reg_decode_mode
Gosub Sai_max
Numero = Reg_intensity
Gosub Sai_max
Numero = Reg_scan_limit
Gosub Sai_max

Do
Waitms 100

If D1 < 9 And D5 <= 9 Then                                  'Comienza conteo 0000 - 9999 y 9999 - 0000

Incr D1
Decr D5
   Elseif D1 = 9 And D2 < 9 And D5 = 0 And D6 <= 9 Then
   Waitms 100
   D1 = 0
   D5 = 9
   Incr D2
   Decr D6

   Elseif D2 = 9 And D3 < 9 And D6 = 0 And D7 <= 9 Then
   Waitms 100
   D1 = 0
   D2 = 0
   D5 = 9
   D6 = 9
   Incr D3
   Decr D7

   Elseif D3 = 9 And D4 < 9 And D7 = 0 And D8 <= 9 Then
   Waitms 100
   D1 = 0
   D2 = 0
   D3 = 0
   D5 = 9
   D6 = 9
   D7 = 9
   Incr D4
   Decr D8

   Elseif D5 > 0 Then
   Decr D5

End If                                                      'Finaliza conteo 0000 - 9999 y 9999 - 0000

Digitos(8) = D8
Digitos(7) = D7
Digitos(6) = D6
Digitos(5) = D5
Digitos(4) = D4
Digitos(3) = D3
Digitos(2) = D2
Digitos(1) = D1

Gosub Mostrar
Wait 1

Loop

Mostrar:
   Numero = 0
   For I = 8 To 1 Step -1
     Numero = Digitos(i)
     Select Case I
       Case 1
         Numero = Numero Or &B1111100000000000
       Case 2
         Numero = Numero Or &B1111011100000000
       Case 3
         Numero = Numero Or &B1111011000000000
       Case 4
         Numero = Numero Or &B1111010100000000
       Case 5
         Numero = Numero Or &B1111010000000000
       Case 6
         Numero = Numero Or &B1111001100000000
       Case 7
         Numero = Numero Or &B1111001000000000
       Case 8
         Numero = Numero Or &B1111000100000000
     End Select
     Gosub Sai_max
   Next I
Return

Sai_max:
  Max_data = 0
  Max_clock = 0
  Max_load = 0
  Shiftout Max_data , Max_clock , Numero , 1
  Max_load = 1
Return

End

 

this is all that we have here, I really want to thank you for all the support already given, I hope that it can continue until it is finished, and leave everything documented for anyone who can achieve it after following me

 

 

 

 

 

 

 

 

 

Attachment(s): 

Last Edited: Tue. May 3, 2022 - 06:15 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That sounds easily possible in Bascom. There are a few regular contributors who use Bascom who should be able to help. 

 

You need to sketch out a specification for what you want to achieve. Obviously I guess you'll want a timer that accurately counts seconds. Some button input reading code and some output display code. The latter is going to be the most complex bit of all so what kind of display do you want to present? 7-segment LEDs perhaps? If so how many digits? Or do you want to display on LCD? If so is it enough to use a couple of lines of characters? Or do you want to go all out and display something looking like an analogue clock by drawing pixels to show the 60 second markings, pointers etc? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Greetings and Welcome to AVR Freaks,

 

I would start by writing down all the things that a chess clock does. There is a button that the players push, right? What happens when that button is pushed? Then, what happens while the timer runs? Then what happens when the timer times out?  Does it have to do anything else like indicate which player the timer is active for?

 

You might look in the tutorial section for tutorials on "state machine" or "finite state machine" or "FSM".

 

If you can make it so that one timeout interval fits all games, then you don't have to change the length of the interval, and it becomes really easy. If you have to be able to set that interval, then start out with the interval time as a variable. Once the timer is working, you can then figure out how to load different timer values into the machine, maybe via USB from another computer. That raises the complexity level pretty high for a starter-project, though.

 

Good luck on your project.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Sat. Apr 9, 2022 - 09:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Start hardware design with 2x20pF and a tiny crystal of 32kHz, soldered to PB6 and PB7.

Then, set AS2 of ASSR.

 

This will produce precise 1Hz, the rest is easy /hope/.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to the Forum.

 

Are you using an Arduino Nano or another Arduino HARDWARE, even though you are not using the Arduino language for the programming?

 

M238, M328p, M328pb ???  There are several versions of the Mega328, and it does matter which one you are using.

 

Have you done some other programs with Bascom and the M328?

(Flashed an LED, read a push button switch, etc.)

 

Have you ever used an interrupt subroutine, for example an interrupt that fires once every 5 mSec?

 

As asked above, what are you going to use for the display?

 

How many days / weeks / months do you have to complete this project?

 

JC

 

Last Edited: Sun. Apr 10, 2022 - 01:01 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey, no, i have to do a custom board, the atmega 328p is the one im ussing, i have done other programs but they are not complex at all, i never done a subrounite interrupt, for the display im using a 7 segments led 4 for each timer ( for minutes and seconds), i have a time lapse of 7 months, i have to end in november. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello, its not that complex the idea its to have 2 display made of 7-segments led display ( so they can show minutes and seconds so they 4 digits each one) and havien 2 butons to pass the time to the other player, another one for restarting the timers and, one for turn on and off, but nothing more, the principal idea its that, maybe some mode that you can change the time from 2minutes to 5 if you whant somenting like that, nothing more

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello, the idea its the clock have 2 displays made out with 7-segments displays (4 for each one, to show minutes and seconds) 2 buttons to activate the other player timer, when it gets to zero it just end determinating that the player has lost, a button to reset the timers, and nothing more maybe a buton that can make change the time from 2 minutes to 5 minutes for example. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


xXThiagox3dDXx wrote:
the idea its the clock have 2 displays made out with 7-segments displays (4 for each one, to show minutes and seconds)

For the displays, is it allowed to use these ones? Two of these can be controlled from two wire interface known as I2C. But this means you have to use TM1637 library. 

 

“Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?” - Brian W. Kernighan
“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint-Exupery

Last Edited: Sun. Apr 10, 2022 - 03:01 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

xXThiagox3dDXx wrote:
show minutes and seconds

 

It should be also hours, guess.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, that ones are allowed, that library i supose that is for bascom, where did i get it? And another question? They are easy to use? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, isnt whort the rule of chess say that the normal time is 10 minutes for each player, 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use 7S LED display. Either 2 modules, or discrete components (8 singles, or 4 double or 2 quadruple).

What is your choice?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My bad I didn't read bascom earlier, so library is no go. Does not exist.

“Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?” - Brian W. Kernighan
“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint-Exupery

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would likely start with a Nano on a breadboard, to work out the hardware and the software, (build a prototype).

 

When it works, then work on a PCB for the project, which is a big project on its own if you haven't done that before.

 

Heisen showed a 4 digit, 7-Segment, display with an I2C interface.

They also come with an SPI interface and a Max 7219 driver chip built into the little display board.

I would use the SPI interface and the Max 7219 driver chip.

You can put both of the displays on the same SPI bus, and have a separate Chip Select line to control which one the micro is sending data to.

 

Those displays, by the way, draw a lot of current.

The little 5V regulator on a Nano won't power the Nano and two of those 4 digit displays, so they will need their own power supply.

(You need a power supply for the displays and the Nano)

 

Draw a Box Diagram of the project.

The Micro, (or the Nano, for starters); the power supply, the two displays, 4 push button switches, a piezo beeper, and an LED or two.

See how many I/O pins the project will require, and make sure that you have enough I/O pins for it all.

 

If you break the project down into small parts then it will all be doable.

 

JC 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, thats sounds nice, im thinking that im not sure how to pass the data from the chip to show in the display, i mean i dont know how to make the display show the time, sorry for asking a lot, i try to be not so heavy whit the questions 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As said above those display modules have their own little intelligent micro ("backpack") on board so the AVR you program will "talk" to them by sending commands like "set digit 2 to show a 9"and that kind of thing. The actual connection is either two wire (clock and data) known as inter-integrated-circuit (IIC or usually I2C) or three wire (clock, data out, data in) known as serial peripheral interface (SPI). Most AVR have separate internal blocks that can do I2C or SPI. So whatever display module you choose you should be covered but make sure to pick either a mega AVR or an Xmega AVR. Don't pick a Tiny AVR. They may look smaller, cheaper, less complex but they don't have things like I2C/SPI but a half arsed thing called USI that makes doing either MORE complicated.

 

In a previous post I said the display would be the most complex part of the design. It is. It's going to be quite a challenge if this is your first AVR project! 

 

At least using four grouped 7 segs with their own controller takes away some of the complexity. If you were trying to connect eight 7-seg displays direct to the AVR it would get very complex indeed! 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, now for geting the reading of the time i was thinking of an rtc a (real time clock) the avr whit the all funcionts working will dilate the time so 5 minutes for the avr will no be 5 minutes real, so i thinked for clock data using one of those, for the leds i think 2 7sleds of 4 each one should do the trick, for making the leds i should multiplex ? my teacher talked about that but i dont sure how it works 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

xXThiagox3dDXx wrote:

No, isnt whort the rule of chess say that the normal time is 10 minutes for each player, 

 

I find this :

Time controls for the World Championship games are 120 minutes for the first 40 moves, followed by 60 minutes for the next 20 moves and then 15 minutes for the rest of the game with an increment of 30 seconds per move starting on move 61.

You could display mm.ss and mmm.f  when over 99 minutes.

 

xXThiagox3dDXx wrote:

Hey, no, i have to do a custom board, the atmega 328p is the one im ussing, i have done other programs but they are not complex at all, i never done a subrounite interrupt, for the display im using a 7 segments led 4 for each timer ( for minutes and seconds), i have a time lapse of 7 months, i have to end in november. 

Does your board include those 7 segment LEDs, or do you need to build an add-on ?

 

I did see this go past at Adafruit  - a nice LCD numeric display.  ( but currently showing out of stock ..)

https://www.adafruit.com/product...

 

Addit: Similar, but available and a bit cheaper is this 10-Digit 16-Segment LCD Display Module 

https://www.aliexpress.com/item/...

Last Edited: Sun. Apr 10, 2022 - 09:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

xXThiagox3dDXx wrote:
the leds i should multiplex

 

I did it many times. Start with CA or CC choice (Common Anode/Cathode).

For CA, I am using 74HC138, and 8 PNP transistors or tiny Mosfets. This, because you have 8 columns and 8 rows, a total of 16 pins.

With HC138 the number is reduced to 12 pins, which is affordable for any ATmega.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can make it all in the same board, but i think is more practical to have it in another just to make it more ergonomic

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
M238, M328p, M328pb ???  There are several versions of the Mega328, and it does matter which one you are using.
AVRe+ is long lead time whereas some AVRxt is less especially AVR Dx; if the tech school has enough stock, including spares for FUBAR, then no issue.

AVRxt :

  • easier to recover than AVRe+
  • increased reliability (injection current)

BASCOM-AVR has some (most?) AVRxt.

 

Lead Time | World's Largest Inventory of Microchip Products

MEGAX | BASCOM-AVR

AVRX | BASCOM-AVR

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

grohote wrote:
Use 7S LED display.
Are LED sunlight readable?  (sun shade?)

Use case is outdoor table tops or furniture; IIRC, some cities have chess table concrete furniture at parks.

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
I would likely start with ...
Requirements (posts #2 and #3) then proceed to a design; both are ideally executable (requirements on a white board or projection screen during a walk through, design on a PC/notebook/tablet/smart phone/feature phone/workstation/server)

Requirements state the information flow between the machine and the operators and/or other machines; information is defined as data with meaning.

Design is the control and data flows within the machine (hierarchical state machines); when the design is complete, precise, and correct then port to an AVR.

 


Ragel State Machine Compiler

Ragel doesn't have a BASIC code generator.

ragel/src at master · adrian-thurston/ragel · GitHub

Ragel due to

 

modeling - Modern Embedded Software | Quantum Leaps

Dual Targeting and Agile Prototyping of Embedded Software on Windows - Quantum Leaps (the model is executable)

 

edit : BDD is Behavior-Driven Development

Cucumber Open | Software Testing Products and Solutions | SmartBear

Cucumber Open - Get Started with BDD Today | Cucumber

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Thu. Apr 14, 2022 - 02:12 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gchapman wrote:

grohote wrote:
Use 7S LED display.
Are LED sunlight readable?  (sun shade?)

Use case is outdoor table tops or furniture; IIRC, some cities have chess table concrete furniture at parks.

 

 

Good point, plus most chess clocks are battery powered, so low drain matters.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That are the micro you use for multiplexing? Are another one that can be usefull? For multiplexing two 4digits 7segments led

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

xXThiagox3dDXx wrote:
Are another one that can be usefull?
Yes

Smart Alphanumeric Displays (Broadcom)

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

xXThiagox3dDXx wrote:

That are the micro you use for multiplexing? Are another one that can be usefull? For multiplexing two 4digits 7segments led

#20 lists some additional hardware to help the MCU

 

if you want to drive say 8 digits of 7 segment LED, with 8 decimal point options, that's a  matrix of 8 lanes for X + 8 lanes for Y so needs 16 MCU pins .

 

Because one side of that matrix is a 1-of-8  you can save some pins, by using some simple LOGIC parts.

eg 74HC138 is a 3 line to 8 demux, so you can save 5 pins

74HC4017 is a decade one-high counter, so it needs a CLK and reset connection for up to 10 way multiplex. saves 6 pins

74HC595 is a 8 bit shift register, and CLK and DAT connections can support up to 8 way multiplex. saves 6 pins

 

 

The other aspect of LED multiplex is current drive.

if you drive for only 1/8 of the time, 10mA of drive needs 80mA peak per pin, which is outside generic MCU's specs, and outside simple LOGIC parts too.

You can either add discrete transistors/mosfets, or you can buy parts like  PIC6C595, which are 8 bit shifters with 100mA sink drive ability.

 

Or, you might decide that roll-your-own LED array driver is too much work, and instead select a module like

https://www.adafruit.com/product... uses  HT16K33 chip, to do all the work, mounted on a Breakout PCB already : 16x8 LED Matrix Driver

This part has 

•     Operating voltage: 4.5V~5.5V
•     Integrated RC oscillator
•     I2C-bus interface
•     16×8 bits RAM for display data storage
•     Max. 16×8 patterns, 16 segments and 8 commons  (20mA source 160mA sink, so high LED drive is all done for you)
•     R/W address auto increment
•     Max. 13×3 matrix key scanning
•     16-step dimming circuit
•     Selection of 20/24/28-pin SOP package types

 

Since this is for a clock/timer, I'd ask the tutor about using LCD display instead of LED.

 

* Adafruit link corrected. *

Last Edited: Mon. Apr 11, 2022 - 03:20 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

about the real time clock? (rtc) do you know how to opperate it and use it in the project?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

about the real time clock? (rtc) do you know how to opperate it and use it in the project?

That isn't necessary, and is an extra complexity.

 

Typically, one runs the micro with an external crystal, (20 MHz, for example).

That gives you a very precise time base.

 

One then uses one of the micro's timer/counters to generate an interrupt once every 1, or 2, or 5, or 10... mSec.

In this case, an interrupt once every 5 mSec would be a great "timer tic" for the project.

Every interrupt you either set a flag for the Main Loop to process, or just increment a counter within the interrupt routine.

That counter is your master timer, from which you measure your 5 min or 10 minute intervals, etc.

 

The reason you can do this is because a player hits a start button, and that starts the clock.

 

A Real Time Clock chip / module gives you the date and time of day.

You don't need that data.

You just need to count time intervals.

 

JC 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

xXThiagox3dDXx wrote:

about the real time clock? (rtc) do you know how to opperate it and use it in the project?

 

A RTC is somewhat optional here - you certainly should use at least a crystal on your MCU, which your AVR board likely already has ?

( the on chip oscillator will not be precise enough)

 

You do not need the hours/weeks/months/leap year handling of a RTC on a chess clock, and a crystal will give good enough precision for timing players.

Allowing for as RTC means you could re-purpose this later, but a RTC is not a requirement.

 

If you do have to use LED Displays, the current drain to the LEDs will dominate, so you'd set up some multiplex tick like 1ms per step, for a 125Hz refresh rate over 8 scan steps.

eg from a 16MHz crystal, you divide by 16000, to 1ms, then divide again by 1000 to 1 second ticks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gchapman wrote:
outdoor table

 

Then we have no full requirement list. If battery operated- it is another project.

 

LCD or OLED, will not be cheap.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


grohote wrote:

gchapman wrote:

outdoor table

 

 

Then we have no full requirement list. If battery operated- it is another project.

 

LCD or OLED, will not be cheap.

 

LCD segment displays let the OP choose size vs price.

Small LCDs can be quite cheap.

 

For best user experience, I'd choose a larger-end LCD Segment module,  maybe something like this

https://www.aliexpress.com/item/...

 

 

that has a largish 18mm high character 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


I've been reading the wikipedia article on chess clocks with interest. Also this online chess timer proved instructive.

 

I guess you initially thought about making what wikipedia call the crude version with LED displays. I've seen that the majority of digital chess timers use large segment type reflective LCD displays. These have the benefit of microamp level current consumption making reasonable life battery operation with possible.

This is just about the pinnacle of what is offered. I suppose you are looking at something simpler.

 

 

Here's an example 4-digit LCD with colon: https://uk.rs-online.com/web/p/lcd-monochrome-displays/8885657

Drivers with with I2C interface for these displays are available.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

You remind me of their search. Yet, I need to buy something from them sometimes, but search...

 

Disgusting! Aliexpress does have the WORST SEARCH possible. Do specify lcd display, and it will find for you 7-10 pages of LED display.

Whatever you search, it will be more than 5 pages of usual rubbish, blended with old search of yours (perhaps to check if you changed a mind).

 

IMPOSSIBLE to search anything, yet they claim it as 'advanced' search. For example, you can not find atmega* unless you specify exact device, numbers and letters.

(Any similarity with our forum search is NOT a pure coincidence.)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would suggest you break your project in to two clock projects, each one has a start/stop switch and a display, keep it simple, once you have one working as needed, then build the other identical clock and combine the two switches so pushing it starts one clock, stops the other, and vis-versa....  

Good luck with your project.

Jim

 

 

FF = PI > S.E.T

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Who-me wrote:
that has a largish 18mm high character 
12 mm for an overstock(?) segment LCD :

GH-2794P: Arndt Electronics : 7-Digit LCD Positive Reflective with 2 Decimal Points SMD : Opto & Illumination (Jameco)

mega48 drives a 3.5 digit segment LCD :

AN8103 AVR340: Direct Driving of LCD Using General Purpose IO using tinyAVR and megaAVR devices | Application Note | Microchip Technology

which are 13 mm high at Mouser :

3.5 LCD Numeric Display Modules – Mouser

 

In the midst of the AVRe+ shortage, mega329 are in stock.

ATMega329 | Octopart

with AVR Butterfly and a sale at Newark :

ATAVRBFLY | Octopart

 

XMEGA B has a character map segment LCD drive; am surprised at the stock level of this XMEGA as XMEGA are long lead time :

ATxmega64B | Octopart

XMEGA Lead Time, Dec'20 | AVR Freaks

 


edit :

Segmented LCD Solutions | Microchip Technology

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Mon. Apr 11, 2022 - 02:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey, no, i have to do a custom board, 

Whatever you do, do NOT start laying out any board, until you have a fully working version on your breadboard.   You will find and correct many mistakes before then, and a PCB will not allow you to correct big mistakes and afterthoughts.

Note: This is the approach, not the solution.

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Mon. Apr 11, 2022 - 03:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

grohote wrote:

 

You remind me of their search. Yet, I need to buy something from them sometimes, but search...

 

Disgusting! Aliexpress does have the WORST SEARCH possible. Do specify lcd display, and it will find for you 7-10 pages of LED display.

Whatever you search, it will be more than 5 pages of usual rubbish, blended with old search of yours (perhaps to check if you changed a mind).

 

IMPOSSIBLE to search anything, yet they claim it as 'advanced' search. For example, you can not find atmega* unless you specify exact device, numbers and letters.

(Any similarity with our forum search is NOT a pure coincidence.)

 

 

Hehe, yes, it is rather broken.

In this case, after many iterations I found segment LCD search, then sort by price, gives the least broken results. Even then, sort by price is somewhat nominal and random.

 

I suspect they have significant revenue generated by 'jump the queue' payments from companies, as they distort the initial search.

Of course, such short term greed damages things enough to ultimately drive users away.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

True, sort by price does help. Also, try to use Google picture search, you can be surprised how Google can do it.

Of course, some pictures may be obsolete, but, if you specify aliexpress lcd segment you will be rewarded with a lot of offers (Aliexpress itself can not provide).

 

For example such beauty 1.3$

 

 

or this module, 3.5$

 

 

Edit: both are without b/l

Last Edited: Mon. Apr 11, 2022 - 08:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey, a question, how i write the code for the max 7219? the idea is just to show numbers in the screen.  Its in bascom and for the atmega328p im tryng to do this work in proteus for star,t, after maybe traspassing to real life.

Last Edited: Mon. Apr 11, 2022 - 10:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

xXThiagox3dDXx wrote:
max 7219

 

Do you have a module with this chip?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No its the 2 sepearated tje chip for 1 way and the screen for other, anyway i just wanna understand how to code it in bascom

Last Edited: Mon. Apr 11, 2022 - 10:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

grohote wrote:

xXThiagox3dDXx wrote:
max 7219

 

Do you have a module with this chip?

 

do a search…. eBay and Ali express 

 have them

 

jim

 

edit: correct a typo

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Last Edited: Tue. Apr 12, 2022 - 10:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Not for me. I have some Matrix modules with this chip, they are blue and fancy:

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

xXThiagox3dDXx wrote:

Hey, a question, how i write the code for the max 7219? the idea is just to show numbers in the screen.  Its in bascom and for the atmega328p

Could not be simpler...

 

https://www.mcselec.com/index2.p...

Ross McKenzie, Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried that code but it seems to have some errors, have another example?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

xXThiagox3dDXx wrote:
it seems to have some errors
What? Where?

 

Do a search with "7219"... that is not the only mention, for example...

 

https://www.mcselec.com/index2.p...

Ross McKenzie, Melbourne Australia

Last Edited: Mon. Apr 11, 2022 - 11:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey, here i send the picture where the error is shown in the bascom software.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Im havent been capable of making the code work, i serched for examples but they are not very clear, i ask again becose i dont know, how is the function to show number in a 4 digit 7ls display, example, that the screen show the number 1990 just that 1 display, 

 

Its in the atmega328p 

Written in bascom 

And the micro max7219 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try this In Portuguese :

 

Tutorial sobre programação com Bascom
 

And this for teaching about Multiplex :

 

Tudo sobre Leds e displays de Leds Multiplexados
 

Paulo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joenic-ou wrote:

Hey, here i send the picture where the error is shown in the bascom software.

... and as the error message says... the variable has not been declared... declare it.

Ross McKenzie, Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

xXThiagox3dDXx wrote:
I tried that code but it seems to have some errors, have another example?

Oh dear. This is worrying.

 

Although the code in that linked example leaves room for improvement (no segment definitions and mixed Capitalised / lowercase variable names) it's fine as a demo.

However; you really should have been able to fix that trivial error. You dismiss the code far too quickly in search of another example.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joenic-ou wrote:
Hey, here i send the picture where the error is shown in the bascom software.

Shouldn't that NEXT statement below the error line be:

NEXT Digit8

 

Jim

 

 

FF = PI > S.E.T

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

im new, im putting my best in this sorry if i couldnt see where the problem is, i will review the code again and look if i can solve it

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Running the AtMega328 at 16MHz, what is common on the small nano and mini Arduino board ($6 at AliExpress), just set the fuses to not divide clock/8. You can run TimerCounter1 in compare mode (interrupt when reaching 62500), at full clock, the interrupt will happens 256 times per second.  In the interrupt routine just decrement a counter from $00 and see it if reaches $00 again, means exactly 1 second. When this happens, just verify which button is pressed and increment the seconds counter for that button.  If the seconds reach 60, zero it and increase minutes.  Send the counters numbers to the display.  Use a Max7219 to make it easier to light the 7 segments display. Reset the counters to zero on power on. If you know assembly language, all of this can be done and tested in 30 minutes.

Wagner Lipnharski
Orlando Florida USA

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The main post was edited to show the most current of the project, and to make it easier and easier to access information 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You seem to be missing some important steps in your design process.

 

You have made the classic mistake of diving in and writing code without giving any thought to actually designing the code. Where are your flowcharts or similar? Where are your snippets (small pieces) of test code?

 

It's a good job I don't teach as I'd fail anyone who only presented working code.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

I don't know Bascom but it might be an idea to see if the editor has a way to show line numbers. However in:

 

 

It is pretty evident that the line in red must be line 167 which is the line to which all four listed errors refer. So just red what it is telling you about that line:

 

"wrong data type"

"unknown variable"

"variable not dimensioned"

 

(ignore the last about "NEXT expected" - that is just a consequence of the first three errors).

 

Those errors are all talking about "Digit8". It's maybe not surprising as it's the only thing really mentioned on line 167 apart from standard BASIC keywords like "FOR" and "TO".

 

Again I don't know Bascom but it did not take me long to find:

 

https://avrhelp.mcselec.com/lang...

 

On that page you will read:

Before assigning a variable, you must tell the compiler about it with the DIM statement.

Dim b1 As Bit, I as Integer, k as Byte , s As String * 10

This is not unlike the C programming language too; before a variable can be used it must be declared in some way so that the language knows what type it is, how much storage to set aside for it  and how how to treat it in subsequent operations. Adding "+ 1" to a "byte" or "integer" is going to be quite different to performing "+ 1" in a string for example!

 

So clearly

Sub Buff_out(byval Disno As Byte)

For Digit8 = 1 To 8

Call Displ_write(digit8 , Seg_buff(disno , Digit8) , Disno)

Next
End Sub

needs to be:

Sub Buff_out(byval Disno As Byte)

Dim Digit8 As Byte

For Digit8 = 1 To 8

Call Displ_write(digit8 , Seg_buff(disno , Digit8) , Disno)

Next
End Sub

However, even before that is added perhaps alarm bells should have been ringing as there are clues here that this is NOT very well written code. A good programmer will use indentation to show the flow of execution. The fact that all the lines are left aligned suggests someone is sloppy and not putting much effort into the code so I would be suspicious of the code anyway. It probably should look more like:

Sub Buff_out(byval Disno As Byte)

    Dim Digit8 As Byte

    For Digit8 = 1 To 8
        Call Displ_write(digit8 , Seg_buff(disno , Digit8) , Disno)
    Next
End Sub

By the way, earlier in the code you will see an example:

Sub No_op(byval T As Byte)
 Local C As Byte
 Local H As Word

 H = 0
 For C = 1 To T
  Shiftout Ser_data , Ser_clk , H , 1 , 16 , 10
 Next C
End Sub

What this shows you is that there is an alternative to "Dim" which is "Local". Again, you would need to read more of that manual I just linked to but I imagine (a bit like local variables in C) that using "Local" instead of "Dim" just makes a more efficient (possibly!), more isolated/localised variable and is probably preferable to "Dim" which is more likely used for "global" variables. So the sub routine might be better as:

Sub Buff_out(byval Disno As Byte)

    Local Digit8 As Byte

    For Digit8 = 1 To 8
        Call Displ_write(digit8 , Seg_buff(disno , Digit8) , Disno)
    Next
End Sub

The fact that someone posted that code to a message board without having actually compiled/tested it (or they would have seen the same error you did) is, again, not a great sign.

 

Last Edited: Tue. Apr 19, 2022 - 08:43 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One more little detail:  If you're actually trying to build a chess clock, spend some money and get good and durable pushbuttons.  If you use the cheapest electronic junk buttons, your chess players will want to strangle you.

 

Get good buttons.  S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Scroungre wrote:

One more little detail:  If you're actually trying to build a chess clock, spend some money and get good and durable pushbuttons.  If you use the cheapest electronic junk buttons, your chess players will want to strangle you.

 

Get good buttons.  S.

I agree. Arcade game buttons were designed to take abuse day in day out.

Ross McKenzie, Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hey actually before doing some flowcharts and doing things like that i just wanted to ensure miself that i can show numbers in 2 screens, so i can actually see if it possible to do. just that

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

that is actually a good idea im not pretty sure how many time a player push a button but if they are cheap they probably are gonna break easy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

our teacher ask us every monday what can promise to him and he ussualy give a instruction, for this week the idea is to show 4 numbers in each screen using the max7219

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hey man your pdf been really usefull, but i dont quite understand how the tabelas work for the max 7219 and how i program it you can explain me that?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

xXThiagox3dDXx wrote:
$Crystal=16000000

 

No, you do not need 16M on device powered by an accu. You need not 16M or 8M xtall at all.

But, you need 32kHz crystal, see in my #4. It will be connected instead of this 16M crystal, and then you will get 1s source for timer.

 

If MAX displays are used, a system frequency can be 4M or perhaps 1M (I have timers with blue MAX and this frequency). Definitely not 16M.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

valusoft wrote:

Scroungre wrote:

One more little detail:  If you're actually trying to build a chess clock, spend some money and get good and durable pushbuttons.  If you use the cheapest electronic junk buttons, your chess players will want to strangle you.

 

Get good buttons.  S.

I agree. Arcade game buttons were designed to take abuse day in day out.

 

Or perhaps use those huge red emergency stop buttons. They also have to be able to take a pounding because of their function, and would be easy to hit.

Wayne

East London
South Africa

 

  • No, I am not an Electronics Engineer, just a 54 year old hobbyist/enthusiast
  • Yes, I am using Proteus to learn more about circuit design and electronics
  • No, I do not own a licensed copy of Proteus, I am evaluating it legitimately
  • No, I do not believe in software or intellectual property piracy or theft
Last Edited: Thu. Apr 21, 2022 - 07:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

WayneZA wrote:
Or perhaps use

 

...a wooden swing, two small magnets and two reed-relays. Will last forever, and btw. a swing position is visible.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

grohote wrote:
a swing position is visible.

The picture (the smaller of the two images) of a Luxury Chess Clock I posted back in #34 has a giant rocker switch. Very visible as to whose turn it is.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That are the micro you use for multiplexing? Are another one that can be usefull?

mobdro
 

vidmate
 

Last Edited: Sat. Apr 30, 2022 - 08:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


N.Winterbottom wrote:
a Luxury Chess Clock I posted back in #34 has a giant rocker switch

 

It is a heritage from analogue clock times, such switch is still welcome today.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I put the program reduced to only show the 4 digits in your other post about ATMEGA328 and MAX7219. See the two examples I put in the program.

 

Is very ease now, you only need to put the 4 numbers in the array Digitos(), and call a subroutine. I don't believe that you don't have success modifying my small code....

 

My friend, Bascom is very easy to use and understand, you only must dedicate a small time to use it.

 

I have programs in comercial products that almost completes the 32K of Program Area of Atmega328, mixed with a lot of Assembly code, all works very well for some years.

 

Make a good decision to you : study more and practice more !

 

Paulo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

acct we already make the multiplexing and make the two screens work, the code is here

$crystal = 8000000

$regfile = "m328Pdef.dat"

$hwstack = 40
$swstack = 32
$framesize = 52

Dim Digitos(8) As Byte

Dim Numero As Word
Dim I As Byte

Const Reg_decode_mode = &B1111100111111111
Const Reg_scan_limit = &B1111101111111111
Const Reg_intensity = &B1111101011111111
Const Reg_shutdown = &B1111110011111111



Config Portc.0 = Output
Config Portc.1 = Output
Config Portc.2 = Output

Max_data Alias Portc.0
Max_load Alias Portc.1
Max_clock Alias Portc.2






Max_load = 1
Numero = Reg_shutdown
Gosub Sai_max
Numero = Reg_decode_mode
Gosub Sai_max
Numero = Reg_intensity
Gosub Sai_max
Numero = Reg_scan_limit
Gosub Sai_max


Do
Digitos(8) = 1
Digitos(7) = 1
Digitos(6) = 0
Digitos(5) = 0
Digitos(4) = 1
Digitos(3) = 8
Digitos(2) = 9
Digitos(1) = 9
Gosub Mostra
Wait 2

Digitos(8) = 1
Digitos(7) = 0
Digitos(6) = 0
Digitos(5) = 0
Digitos(4) = 0
Digitos(3) = 0
Digitos(2) = 0
Digitos(1) = 0
Gosub Mostra
Wait 2

Loop


Mostra:
   Numero = 0
   For I = 8 To 1 Step -1
     Numero = Digitos(i)
     Select Case I
       Case 1
         Numero = Numero Or &B1111100000000000
       Case 2
         Numero = Numero Or &B1111011100000000
       Case 3
         Numero = Numero Or &B1111011000000000
       Case 4
         Numero = Numero Or &B1111010100000000
       Case 5
         Numero = Numero Or &B1111010000000000
       Case 6
         Numero = Numero Or &B1111001100000000
       Case 7
         Numero = Numero Or &B1111001000000000
       Case 8
         Numero = Numero Or &B1111000100000000
     End Select
     Gosub Sai_max
   Next I
Return

Sai_max:
  Max_data = 0
  Max_clock = 0
  Max_load = 0
  Shiftout Max_data , Max_clock , Numero , 1
  Max_load = 1
Return


End

now we are doing a counter from 0 to 9999 and one from 9999 to 0000, to ha testing in the screens, we have a working code for the 2 screens, sugest on how to do the code

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What you don't have is any comments !!

 

No one here knows your code so we can only guess at what those fixed numbers like:

B1111011100000000

might be used for? A comment explaining what's going on will be helpful for people like us to understand what your program is doing.

 

Now you may not think this matters but when you (or your code maintainer!) come back to this in 18 months some help to understand what was in the author's mind at the time it was written will be VERY helpful!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

The basic code was described in my tutorial about Multiplexing, to help people with little knowledge about Led displays and matrices.

In the text, I explained the use of the values sent to Max7219.

 

Sorry about my fault in make better documentation directly in code.

 

Paulo

 

Last Edited: Fri. Apr 29, 2022 - 12:32 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good to see that you are making progress !

 

Congratulations !

 

Paulo

Last Edited: Fri. Apr 29, 2022 - 12:36 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello, basically that code puts the screens to work through the max 7219, the parts that put b111000 etc, are the configuration of the max, these are made up of 16 digits and based on what you put in some specific digits indicated in the datasheet, you can configure the lighting, the number of digits to read, etc. the pdf that explains the work is in spanish, but anyonbe can translate whit some search in google 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello, query, I want to implement a counter from 0 to 9999 in my program, the problem is that the screen is separated by digits, that is digit 1 = 0 digit 2 = 0 digit 3 = 0 digit 4 = 0 I mean I can't just put a variable that replaces the digit and add one to it, I have to increase each number up to nine, return it to 0 and so on to count up to 9999, I came up with a mean bad idea that nothing else allows me to count up to 10 by which then starts to count wrong, any idea how to do it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

xXThiagox3dDXx wrote:

acct we already make the multiplexing and make the two screens work, the code is here...

now we are doing a counter from 0 to 9999 and one from 9999 to 0000, to ha testing in the screens, we have a working code for the 2 screens, sugest on how to do the code

 

that post say you have working code ?

xXThiagox3dDXx wrote:

hello, query, I want to implement a counter from 0 to 9999 in my program, the problem is that the screen is separated by digits, that is digit 1 = 0 digit 2 = 0 digit 3 = 0 digit 4 = 0 I mean I can't just put a variable that replaces the digit and add one to it, I have to increase each number up to nine, return it to 0 and so on to count up to 9999, I came up with a mean bad idea that nothing else allows me to count up to 10 by which then starts to count wrong, any idea how to do it?

 

but then this post suggest you have problems ?

 

Usually for clocks as counters, the simplest is to allocate a BYTE sized variable per digit, and to manage the increment and decrement with overflows in SW.

The overflow varies, depending on which digit it is.

 

Along the lines of 

 

If you display HH:MM lets call that Hh:Mm to give each a unique letter.

m increments 0..9 and when = 10, replace with 0 and  increment M.

When M increments to 6, replace it with 0 and increment h  (thus highest could is 59 -> 00)

When h increments = 10, replace with 0 and  increment H.  (24 hr clock)

When H,h is 2,4 replace with 0,0 (thus highest is 23:59) for a 24 hour clock.

 

You then directly display HhMm on the LEDs

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hey we already maked the 2 counters, ill show the code working, the coments are in spanish sorry.. you can translate them whit google

$crystal = 8000000

$regfile = "m328Pdef.dat"

$hwstack = 40
$swstack = 32
$framesize = 52

Dim Digitos(8) As Byte          'Se dimensiona variable array con 8 elementos tipo byte
Dim Numero As Word
Dim I As Byte



Dim D1 As Byte
Dim D2 As Byte
Dim D3 As Byte
Dim D4 As Byte
Dim D5 As Byte
Dim D6 As Byte
Dim D7 As Byte
Dim D8 As Byte                                              'dimension variable byte para el valor de cada dígito

D1 = 0
D2 = 0
D3 = 0
D4 = 0

D5 = 9
D6 = 9
D7 = 9
D8 = 9

Const Reg_decode_mode = &B1111100111111111
Const Reg_scan_limit  = &B1111101111111111
Const Reg_intensity   = &B1111101011111111
Const Reg_shutdown    = &B1111110011111111


Config Portc.0 = Output                        'Configuración puerto C como salida
Config Portc.1 = Output
Config Portc.2 = Output

Max_data Alias Portc.0
Max_load Alias Portc.1
Max_clock Alias Portc.2



Max_load = 1
Numero = Reg_shutdown
Gosub Sai_max
Numero = Reg_decode_mode
Gosub Sai_max
Numero = Reg_intensity
Gosub Sai_max
Numero = Reg_scan_limit
Gosub Sai_max


Do
Waitms 100

If D1 < 9 And D5 <= 9 Then                                  'Comienza conteo 0000 - 9999 y 9999 - 0000

Incr D1
Decr D5
   Elseif D1 = 9 And D2 < 9 And D5 = 0 And D6 <= 9 Then
   Waitms 100
   D1 = 0
   D5 = 9
   Incr D2
   Decr D6

   Elseif D2 = 9 And D3 < 9 And D6 = 0 And D7 <= 9 Then
   Waitms 100
   d1 = 0
   d2 = 0
   d5 = 9
   d6 = 9
   incr d3
   decr d7

   Elseif D3 = 9 And D4 < 9 And D7 = 0 And D8 <= 9 Then
   Waitms 100
   D1 = 0
   D2 = 0
   D3 = 0
   D5 = 9
   D6 = 9
   D7 = 9
   Incr D4
   Decr D8

   Elseif D5 > 0 Then
   Decr D5

endif                                       'Finaliza conteo 0000 - 9999 y 9999 - 0000


Digitos(8) = d8
Digitos(7) = d7
Digitos(6) = d6
Digitos(5) = d5
Digitos(4) = d4
Digitos(3) = d3
Digitos(2) = d2
Digitos(1) = d1


Gosub Mostrar
Wait 1


Loop


Mostrar:
   Numero = 0
   For I = 8 To 1 Step -1
     Numero = Digitos(i)
     Select Case I
       Case 1
         Numero = Numero Or &B1111100000000000
       Case 2
         Numero = Numero Or &B1111011100000000
       Case 3
         Numero = Numero Or &B1111011000000000
       Case 4
         Numero = Numero Or &B1111010100000000
       Case 5
         Numero = Numero Or &B1111010000000000
       Case 6
         Numero = Numero Or &B1111001100000000
       Case 7
         Numero = Numero Or &B1111001000000000
       Case 8
         Numero = Numero Or &B1111000100000000
     End Select
     Gosub Sai_max
   Next I
Return

Sai_max:
  Max_data = 0
  Max_clock = 0
  Max_load = 0
  Shiftout Max_data , Max_clock , Numero , 1
  Max_load = 1
Return

End

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See if this might help you.

Happy Trails,

Mike

JaxCoder.com => PartsBin - An Electronics Component Organizer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

now we are thinking how to do two buttons, when you press one one clock will start and the other will stop, and the other do the same 

 

 

example, the two counters are stoped,  when i push the button of the rigth the counter in the left will start, then when  i push the left button the left counter stops and then the rigth counter starts, any ideas 

$crystal = 8000000

$regfile = "m328Pdef.dat"

$hwstack = 40
$swstack = 32
$framesize = 52

Dim Digitos(8) As Byte                                      'A variable array with 8 byte type elements is dimensioned
Dim Numero As Word
Dim I As Byte



Dim D1 As Byte
Dim D2 As Byte
Dim D3 As Byte
Dim D4 As Byte
Dim D5 As Byte
Dim D6 As Byte
Dim D7 As Byte
Dim D8 As Byte                                              'dimension variable byte for the value of each digit

D1 = 0
D2 = 0
D3 = 0
D4 = 0

D5 = 9
D6 = 9
D7 = 9
D8 = 9

Const Reg_decode_mode = &B1111100111111111
Const Reg_scan_limit = &B1111101111111111
Const Reg_intensity = &B1111101011111111
Const Reg_shutdown = &B1111110011111111


Config Portc.0 = Output                                     'Configuration port C as output
Config Portc.1 = Output
Config Portc.2 = Output

Max_data Alias Portc.0
Max_load Alias Portc.1
Max_clock Alias Portc.2



Max_load = 1
Numero = Reg_shutdown
Gosub Sai_max
Numero = Reg_decode_mode
Gosub Sai_max
Numero = Reg_intensity
Gosub Sai_max
Numero = Reg_scan_limit
Gosub Sai_max


Do
Waitms 100

If D1 < 9 And D5 <= 9 Then                                  'Start counting 0000 - 9999 and 9999 - 0000

Incr D1
Decr D5
   Elseif D1 = 9 And D2 < 9 And D5 = 0 And D6 <= 9 Then
   Waitms 100
   D1 = 0
   D5 = 9
   Incr D2
   Decr D6

   Elseif D2 = 9 And D3 < 9 And D6 = 0 And D7 <= 9 Then
   Waitms 100
   D1 = 0
   D2 = 0
   D5 = 9
   D6 = 9
   Incr D3
   Decr D7

   Elseif D3 = 9 And D4 < 9 And D7 = 0 And D8 <= 9 Then
   Waitms 100
   D1 = 0
   D2 = 0
   D3 = 0
   D5 = 9
   D6 = 9
   D7 = 9
   Incr D4
   Decr D8

   Elseif D5 > 0 Then
   Decr D5

End If                                                      'End count 0000 - 9999 and 9999 - 0000


Digitos(8) = D8
Digitos(7) = D7
Digitos(6) = D6
Digitos(5) = D5
Digitos(4) = D4
Digitos(3) = D3
Digitos(2) = D2
Digitos(1) = D1


Gosub Mostrar
Wait 1


Loop


Mostrar:
   Numero = 0
   For I = 8 To 1 Step -1
     Numero = Digitos(i)
     Select Case I
       Case 1
         Numero = Numero Or &B1111100000000000
       Case 2
         Numero = Numero Or &B1111011100000000
       Case 3
         Numero = Numero Or &B1111011000000000
       Case 4
         Numero = Numero Or &B1111010100000000
       Case 5
         Numero = Numero Or &B1111010000000000
       Case 6
         Numero = Numero Or &B1111001100000000
       Case 7
         Numero = Numero Or &B1111001000000000
       Case 8
         Numero = Numero Or &B1111000100000000
     End Select
     Gosub Sai_max
   Next I
Return

Sai_max:
  Max_data = 0
  Max_clock = 0
  Max_load = 0
  Shiftout Max_data , Max_clock , Numero , 1
  Max_load = 1
Return

End

now the coments are in english so you can understand it, the part select case and everything whit b000001111 etc, just ingor it is for the max7219 work 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My suggestion :

 

You have two powerful interrupts : INT0 and INT1, attach a button on each pin to ground, and use interrupts to detect the press, and set/reset flags to be read in the main program.

Bascom have all high level instructions to make this easy.

 

Paulo

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

xXThiagox3dDXx wrote:

now we are thinking how to do two buttons, when you press one one clock will start and the other will stop, and the other do the same 

example, the two counters are stoped,  when i push the button of the rigth the counter in the left will start, then when  i push the left button the left counter stops and then the rigth counter starts, any ideas 

 

Google Set/Reset flip flop or latch, and duplicate the operation in software. If you need Stop(preset)/DownL/DownR, you will need 2 boolean variables.

 

With just 2 alternating states, you do not need to do complex debounce, but you may want to think about other operations like  Pause and reset time or set time - what does your tutor say about those functions ?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

exactly what do you mean, I mean I declare 2 pin variables for the buttons, example config pinb.o = input So I have to put interrupts? I googled INT0 and INT1 and the bascom page came out but I didn't understand very well how they work, and what are the set reset flags?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

aphawk wrote:
You have two powerful interrupts : INT0 and INT1, attach a button on each pin to ground, and use interrupts to detect the press, and set/reset flags to be read in the main program.
Usual advice is NOT to attach buttons to external (INT0/INT1) interrupts as button contacts bounce and you will get multiple interrupts in a short burst for single make/break.

 

Two solutions - if you are going to use INT0/INT1 then employ a few external (RC) components on the buttons to do debounce in hardware OR just poll the state of the buttons in a a timer interrupt - only consider the button settled into a fixed state when it has been seen in the same state for several consecutive interrupts.

 

(even if you don't use interrupts you will have to be thinking about bounce!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Start with a state diagram. You should control which button is pressed first, the cases of the second button is pressed during first one is active...

Go on, and forget the interrupt, check the button state each 5-10 ms.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We talked about Rocker Switches previously. Have you decided on latching or non-latching button/switch. A DPST toggle switch may work nicely.

Either way, you DON'T want interrupts.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

N.Winterbottom wrote:

Either way, you DON'T want interrupts.

 

There's a product out there (well, was, it has been superseded) that contained no less than 30,000 lines of my finest AVR assembler code, and not a single interrupt handler.  I made the decision very early on that because an awful lot of the interfaces were time-sensitive, that there wouldn't be any interrupts, ever.

 

I'm not entirely sure that was the correct decision.  Still, it did lend to a great deal of predictability - if not simplicity.  S.