Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
January 17, 2019, 09:29:31 21:29


Login with username, password and session length


Pages: 1 [2]  All
Print
Author Topic: MikroC for PIC using Proteus (zuisti's solutions)  (Read 41662 times)
0 Members and 1 Guest are viewing this topic.
zuisti
Senior Member
****
Offline Offline

Posts: 393

Thank You
-Given: 228
-Receive: 705


« Reply #25 on: September 16, 2017, 11:31:40 11:31 »

                    Compiler: mikroC Pro for PIC v6.01
         Proteus-only projects, using 2x16 LEDs and/or a 4x20 LCD
                         Istvan K (zuisti), 2017

I made four projects that are in different folders:
  16F88_LED            18-pin PIC, 2x16 leds, exact timed multiplexing
  44K22_LED            40-pin PIC, non-multiplexed (direct) led control
  16F684_LCD          14-pin PIC, 4x20 LCD
  44K22_LCD-LED     LCD and LEDs, both at a time (see the video)

Common features:
- runtime switchable characteristic:
   lin:   6 to 100 %
   log: -36 to +12 dB, 3 dB/step
- a real wav audio file is used as an input (cannot be heard in Proteus)
- adjustable input LEVEL (sensitivity)
- 250 Hz refresh rate (4 ms)

LED bargraph:
- level-dependend LED colours (12 green, 3 yellow, 1 red; a total of 16 leds)

LCD:
- 16 chars wide bargraph using User Defined Chars (UDCs)
- always visible scale-line (part of all UDCs)
- displayed audio channel (R and L) and current unit (% or dB)
- displayed scale values (second line)
- level-dependend shapes (UDCs) to imitate the different led colours
- runtime switchable 3 different sets of shapes (UDCs): three diff. modes
- the first line shows the current characteristic (lin-log) and mode (0-1-2)

For more description see the included "README_FIRST.TXT" (and the source) files.
--------------

A video to show how to works the simulated LED and LCD VU meter
(the "44K22_LCD-LED" project was used, its circuit is attached as a GIF):
https://youtu.be/9ftmeEKwxGA
 
The included wav file greatly increases the size of the RAR (because it is not
really compressible). Therefore, I uploaded the complete RAR to the 4shared page:
https://www.4shared.com/rar/UHvcPpHKei/VUprojs_up.html
« Last Edit: November 04, 2017, 11:16:30 11:16 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 393

Thank You
-Given: 228
-Receive: 705


« Reply #26 on: October 06, 2017, 04:07:55 04:07 »

So far 17 downloads and no any feedback (and only 3 thankyou  Sad ), although I worked hard on it.
I would like to thank someone for a better (more effective) peak-hold algorithm than what I wrote and published.

Since then, I've made a 'one-line' stereo VU meter project, which only uses the bottom line of a 16x2 LCD.
The picture of the working simulation is attached, but I do not want to publish the entire project, sorry.

zuisti
« Last Edit: November 04, 2017, 11:19:12 11:19 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 393

Thank You
-Given: 228
-Receive: 705


« Reply #27 on: November 02, 2017, 04:08:53 16:08 »

16-stage stereo peak hold/decay VU meters, see my post #25 above.
  Attached the expanded and improved version 2.1.

What's new ..

Two new projects:

   the 'one-line' stereo VU meter, in the "ONELINE" folder (see my prev. post)

   on request a 2x10 LED version, in the "16F88_2x10led" folder. See this topic:
   http://www.sonsivri.to/forum/index.php?topic=64785.msg186112#msg186112


Fixes:

   The displaying of the text "lin/log" on the upper LCD line now changes already
   at runtime too (according the jumper).

   New, faster and smaller Lcd_Goto functions (see the "LCD_Lcd0.h").

   Separated "poscalc.h", so it is easier to create multiple instances with
   different names (and different, own static variables).


Each project was recompiled. Read more in the new, improved "README_FIRST.TXT".

Note:
To decrease the size of the uploaded RAR the "test.wav" file is missing in the "wav"
folder (as I wrote it is not really compressible). Please copy from the previous RAR.
Likewise, the video (the AVI file) is also missing as it has not changed.

Greeting,
zuisti
« Last Edit: November 04, 2017, 03:26:44 15:26 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 393

Thank You
-Given: 228
-Receive: 705


« Reply #28 on: November 04, 2017, 03:14:34 15:14 »

My forgotted promise (I apologize) but now I post the full version of the two MMD tasks.
Each "Proteus-only" project is completed with its C source file(s) and the DSN.
The projects were written in mikroC v6.01, using the "case sensitive" mode.

8pin_MMD   rs232 (and CTS) controlled, using a 'virtual' PIC16F683 (due of the COF).  
MMD_Ps2    PIC16F628A MMD circuit, controlled via real/emulated/simulated PS2 keyboard

Read more in my prev. posts (#8 to #11 in this topic).
-  for example see the pictures here:
http://www.sonsivri.to/forum/index.php?topic=52263.msg152862#msg152862

But - sorry - no any 'support', I do not have time. These are 'as-is' projects.

  A question:
- Would you be interest for the source of my PIC18_MMD project? This I've written a
long time ago (in 2012) yet in Proton BASIC. This link shows the features:
http://www.sonsivri.to/forum/index.php?topic=42842.0
If so, I will look in my archive ...

Edit: Found it, uploaded, here you go:
http://www.sonsivri.to/forum/index.php?topic=42842.msg186534#msg186534

Thanks
zuisti (Istvan K)

--------
pickit2: Please Keep this Topic Clean - make replies to posts here:
http://www.sonsivri.to/forum/index.php?topic=64785.0

« Last Edit: November 12, 2017, 03:01:55 03:01 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 393

Thank You
-Given: 228
-Receive: 705


« Reply #29 on: April 14, 2018, 04:55:41 16:55 »

I'm constantly working on my new mikroC libraries. As usual I'm using
family-dependent asm optimizations so the libraries remain closed as before.

Now my new Button library is presented, and attached a complete demo project
which detailly shows the usage. Here is the C source:
Code:
/* Button_demo.c (to show how to use my new Button library)

  Istvan K (zuisti), Apr. 2018

Tried in Proteus using the "628_button_demo.DSN" (PIC16F628A)

  Do not select the standard Button library (name conflict !!), instead
  my new p*_Button.mcl (now p* = p16) is used locally (found in 'lib' folder).
  Simply add the library to the 'Binaries' node in the IDE's 'Project Manager'.

The library allows to use three functions (see also below, in the program):  */

extern char Button(char* port,         // port address (&PORTx)
                   char  pin,          // pin number (0..7)
                   char  DtimeMs,      // debounce time in ms (0-255)
                   char  wantedstate); // 0 or 1
/* exactly the same as the original function (see help) but
   it produces much less code and more useful return values:
if the pin was in the wanted state for the given period then (as the original)
it returns with a nonzero value (and Z_bit will be 0) but this (always nonzero)
value is the internally calculated pin-mask, which is more useful than the 255
(the demo program shows an example how to use this feature).
  Otherwise (ie if no match) it returns 0 and Z_bit will be 1 so this flag
can be tested instead of R0 (less code)  */

extern char WaitPress(char* port,
                      char  pin,
                      char  timelimit, // in 20 ms unit, longpress limit
                      char  pressedstate);
/* blocking function: wait for the keypress with debouncing, 'measures'
the lenght of the keystroke then waits for releasing also with debouncing.
 Returns 1 (and Z_bit = 1) if the lenght is less than the given 'timelimit'.
Otherwise, in case of a 'long' press, it returns 2 and Z_bit will be 0.  */

extern char isPressed(char* port,
                      char  pin,
                      char  timelimit, // timeout and longpress limit
                      char  pressedstate);
/* non-blocking function: wait for the keypress with timeout and debouncing.
The parameter 'timelimit' is used as timeout value also, and if it does not
detect a valid keypress in this time interval (time is off) then returns 0
and Z_bit will be 1. Otherwise, as the above, it 'measures' the lenght of the
keystroke then waits for releasing also with debouncing. In this case Z_bit
is zeroed and returns 1 if the lenght is less than the given 'timelimit', and
returns 2 in case of a 'long' press (lenght of the keypress >= timelimit)   */

// ------------

// a (not so useful :-) demo program to show the usage of the above functions:
void main(void) {

  NOT_RBPU_bit = 0; // portb pullups on (active 0 buttons)

  // WaitPress() is a blocking function so it is placed outside of the main loop
  R7 = WaitPress(&PORTB, 5, 25, 0); // on Rb5, 25*20=500 ms timelimit, 0 active
  // its return value (R7) is watched in Proteus (in the 'Watch' window)
  // ** depending on the specific value we can create more program branches here

  while (1) { // loop time is appr 0.5 sec due to the isPressed() timeout

   if (isPressed(&PORTB, 6, 25, 0)) { // on Rb6, 25*20=500 ms timelimit, 0 active
      R8 = R0; // watched too (1 or 2)
   }
   // next line shows the usage of the Z flag as return value (0: matched)
   else if (Button(&PORTB, 7, 20, 0), !Z_bit) { // Rb7, 20ms debouncing, 0 wanted
      R8 = 0;  // clear the last isPressed() result (apply a long press !!)
   }
   // continuous watching the four dipswitch states using only one variable (R9)
   R9 = 0;
   R9 |= Button(&PORTB, 0, 20, 1); // Rb0, 20ms, 1 wanted  *** and so on ***
   R9 |= Button(&PORTB, 1, 20, 1);
   R9 |= Button(&PORTB, 2, 20, 1);
   R9 |= Button(&PORTB, 3, 20, 1);
   // eg. this is what the new return value (pin-mask, instead of 255) allows.
  }
}
I hope it will be useful also for you, try it out.
zuisti
Here is the Proteus screenshot and the project ZIP


Logged
zuisti
Senior Member
****
Offline Offline

Posts: 393

Thank You
-Given: 228
-Receive: 705


« Reply #30 on: April 28, 2018, 09:20:37 09:20 »


My new "LCD ready" Keypad libraries can be divided into two main categories:
- 4x4 keypad libraries
- 4x3 keypad libraries (having one free port-pin which can be used as LCD_EN)
Both have two versions:
- using column pulldown resistors
- using column pullup resistors (may be internal !)

Of course, all the libraries were made in 3 different versions according to the
3 different PIC families (p16, p16_Enh and p18).

The Keypad libraries are "LCD-ready", which means that the same port can be used
to control an alphanumeric LCD, using the standard mikroC library.

For detailed description look at the attached "8pinKeypad_lib_DOC.H" file.

Attached also a complete demo project to show how to use my new Keypad library.
"LCD, 4x3 (phone) keypad and two momentary buttons: all on one 8-bit port"
- switchable numeric/alpha (upper and lowercase) keypad characters,
- displays a '!' warning char while a button (key) pressed and does not released,
- Proteus simulation, using a standard 4x3 "phone" keypad device and a 16x2 LCD.
A screenshot is also attached.

I hope it will be useful also for you, try it out.
IstvanK
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 393

Thank You
-Given: 228
-Receive: 705


« Reply #31 on: August 26, 2018, 06:27:55 18:27 »

On request I wrote (in 2015) a PIC program to decode and display the standard RC5 remote contoller's signal. As I do not have such controller, to try the program I made also an interactive (8-button) EasyHDL script generator in Proteus to emulate the remote contoller:
one-shot or repeating, idle: HI, true toggle-bit handling, also extended commands ...

For details see the C source file in the attached project.
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 393

Thank You
-Given: 228
-Receive: 705


« Reply #32 on: September 04, 2018, 05:07:16 17:07 »

As on the old (non-smart) phones each keypad button allows us to choose more (here: six) variants.  For example:
-   to choose the 3rd variant (char): short keypress 3 times,
-   6th ie the last variant (often a digit): 1 long keystroke
The 6 variants per button allow you to use the full English ABC and all the punctuation marks.

By default, letters are uppercase (can be changed any time), the lowercase letters in the table (f,b,s,c,t) execute a command. See the picture below and the C source files.
I made a complete Proteus project (attached) to show how to use it. The project is full with sources, it uses only standard mikroC libraries.
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 393

Thank You
-Given: 228
-Receive: 705


« Reply #33 on: September 09, 2018, 05:33:23 17:33 »

The program is waiting for a key to be pressed and then emits its code to the serial (TTL-level RS232) output. After releasing the key, it sends a zero character (in the Proteus an 'r' letter).

Selectable (by a jumper) 4x4 or 4x3 keypad output codes: see picture.

The switchable p12 keypad library (written by me, using a lot of assembly codes) is attached in binary ie MCL form. The operating program is written in mikroC, so it is easy to customize.

This small circuit can be built as a backpack for an existing 4x4 keypad.
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 393

Thank You
-Given: 228
-Receive: 705


« Reply #34 on: November 06, 2018, 09:57:53 09:57 »


Full function alarm clock using a DS1307:

- (only) two-button treatment, 16x2 LCD with I2C 'backpack', blinking alarm LED
- adjustable RTC time-date, the (abbreviated) name of the day too
- settable alarm (status, hours and mins), stored also in RTC user ram
- restore alarm settings at next power-on (remember it if we have RTC battery)
- the alarm lasts for 1 min but can be switch off at the touch of a button
and so on, see the picture, the source files, and try the working simulation.

It's not a big deal to write a program with the above features if you have an MCU with many ROM and RAM, but this little PIC was a real challenge.

The PIC12F629 I'm using is really small, having only 1024 program words and 48 bytes RAM. The program (written in mikroC) occupies almost all the resources:
- Used ROM (program words): 1019 (100%), free: 5 (0%)
- Used RAM (bytes): 41 (85%)  Free: 7 (15%); according to the compiler's "log" file

To do this, I had to use own (very small but fast) Sw I2C and LCD functions, and the applied algorithms are also new (for example, there are no bcd-dec and dec-bcd conversions). True, in this digit-oriented algorithm, the programming of the limits (for ex. the month can only be 1-12) is a bit cumbersome and also the code space is too small so this is not complete but can be used (pay attention).

Even so, I used also some tricks with the FSR (named also as FSRPTR, which is an 1-byte C pointer in the non-enhanced p12/p16 world: less code !) and the INDF (treated as a char pointed by the FSR).

The program itself is very concise, not so easy to understand, although I tried to make many comments. Only for experienced PIC programmers, sorry.

The here applied Sw I2C and LCD functions I tried also in the real world (in another program), they worked well.

----------
However, since I find so that here is no real interest in my simple PIC projects, now I uploaded only the Proteus simulation and the HEX file (compiled especially to taking into account how works the simulated DS1307 device), and look forward to the comments from those who have tried it.

I would be delighted if someone would write a better clock program for this little PIC, but I would also like to welcome any suggestions. Thanks in advance ..

Istvan K (alias zuisti)
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 393

Thank You
-Given: 228
-Receive: 705


« Reply #35 on: December 11, 2018, 05:19:47 05:19 »

  In my previous post I uploaded the working Proteus simulation of my first solution (with PIC12F629), hoping to get some feedback. Well, so far 27 downloads (with 6 thankyou's, thanks :-), but no any response, comment nor advice. That is why I do not upload the entire project, it makes no sense.

  In the meantime, I've been upgrading (finishing?) the Clock project, that I want now to show. As the supplements were not fit in the small PIC, I used the larger PIC12F683, having 2k code memory. Perhaps this may be more interesting, but at least try it out:

Alarm Clock with auto day-of-week calculation:

- the program works as well with the DS1307, DS3231(M) or DS3232 chips (using same HEX)
       to show this, I made a switchable Proteus simulation also (do not switch RTC while runs)

- auto day-of-week calculation and display (also while day, month or year is modified)

- the alarm settings are saved (and restored at next power-on)

- different buttons to increase/decrease the selected value, using its specific limits:
     sec, min: 0 to 59
     hour: 0 to 23 (24 hours mode)
     day: 1 to 31 (or 28 or 29 or 30, depends on the month and year, calculated)
     month: 1 to 12
     year: 1 to 99 (2001 to 2099), leap-year handling

- auto back repair (an interesting problem I faced to, hope it's solved):

 Not as often, but modify of the month can be resulted also an invalid day-value. An example: if the date is 31-12-18 and we modify the month to 11 (November is a 30-day month), then the resulting date (31-11-18) would be invalid. In such cases the program will step back to the day's adjusting (to signalize the repair) and automatically corrects the day's value (in our example the invalid 31 will be 30), so the final date (30-11-18) also will be valid.
This is my solution, the "back repair". Try it out.

I'm really looking forward to your valued comments and advices.
Regards,
Istvan K (alias zuisti)
PS:
I apologize for the bad English.

« Last Edit: December 29, 2018, 03:10:30 15:10 by zuisti » Logged
Pages: 1 [2]  All
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC