Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 08, 2016, 02:56:41 02:56


Login with username, password and session length


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

Posts: 371

Thank You
-Given: 219
-Receive: 567


« on: May 05, 2013, 12:18:28 12:18 »

( More LCD do you want to use? Or more Sw Uart? )


I work more recently in C, using the MikroC Pro for PIC v6. I've created my own libraries (so far only for the PIC16(12) family, but these are continually being improved). The completed and tested very first versions (in binary form but with working examples, projects and documentations too) I uploaded in the compiler's own forum because I thought this was the right place. Unfortunately I was disappointed there was no sense of the thing: only a few negative feedback came, which asked for the library sources. However, this I have no intention, especially in the development phase, and a such open forum.

I am convinced that a lot of beginners and advanced users can use these solutions so, that receive these new libraries in binary form.

My new libraries contain extremely simplified (much smaller code footprint) interface for
-- max two  LCD (4bit mode, 6 pins)
-- max two  LCD (using a HC595, 3 pins)
-- max four  Sw-Uart (1, 2 or 3 pins, CTS handshake)
Also some routines as Hex2out, Dec3out, CstrOut.
A separated library for using them via function_pointer.

-- PC keyboard in Proteus(!!):
To try/debug (before the construction, in Proteus) such PIC programs that use the excellent and easy to use MikroC Ps2_Library, a separated library was created. It uses the Proteus Virtual Terminal as input device to simulate the PC keyboard inputs (keystrokes).
-- all new libraries come with a working example project (also in Proteus, see the picture)
-- a workaround to debug the PIC12F683 in Proteus, using COFF (it does not work now, try it!)


If you have interest, please indicate here (for example,  with a 'thankyou') and I am going to upload them one after the other, as my schedule permits. Or, if the moderators do not complain, and do not overload the server, I can give you the links of the already uploaded things.

Regards
zuisti (Istvan K.)
« Last Edit: May 05, 2013, 12:21:39 12:21 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #1 on: May 05, 2013, 04:43:26 16:43 »

--------------
As promised, here is the first: the Multi Sw-Uart library is presented.

It contains interface for max. four software (bit-banging) uart,

- can be write-only (1wire)
- read function with or without timeout (hw handshake via CTS)
- no need any break() via interrupt + timer
- no any error handling (yet)
- it's small: the simplest read-write loop program (like in the help) is only 67 bytes long
- direct output routines, without any additional buffer (hex2out, dec2out, dec3out, ...)

I wrote a simple program to demonstrate the facilities of the library.
Attached the MikroC project and a well working Proteus simulation.

Note:
In my new libraries for PIC12-16 (like this) I'm not using the pin-direction declarations  because they can be calculated from the pin-declarations (only the bank must be changed).
For example:
Code:
  sbit Stx0_pin  at PORTA.B0;
   //sbit Stx0_pin_direction  at TRISA.B0; //omitted, it is calculated  
So you need to write less  Smiley

Unfortunately this is not possible in case of PIC16enh and PIC18 families  Sad
(respectively, can be solved using indirect addressing, but not worth, too large code).
  
Regards.

UPDATED (but this 'old' also works):
http://www.sonsivri.to/forum/index.php?topic=52263.msg161544#msg161544

« Last Edit: April 17, 2014, 09:30:42 09:30 by zuisti » Logged
towlerg
V.I.P
Active Member
*****
Offline Offline

Posts: 136

Thank You
-Given: 282
-Receive: 48

What is this for?


« Reply #2 on: May 05, 2013, 08:00:47 20:00 »

Very interested in PC keyboard in Proteus.

Rgds  George
Logged

Win 7 Ult x86 SP1 on HP6910p
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #3 on: May 06, 2013, 08:57:43 08:57 »

Very interested in PC keyboard in Proteus.

Hi George;
Thanks but please be patient, it's not yet ready for publication, a small description and some example have to be created.
To avoid any misunderstanding: this is not a new Proteus device but a simulation library that can be used on each PIC16(12) program (without changing it), which is based on the original MikroC PS2_Library. Instead simply my library must be used when compiling the project.

HW usage (in Proteus):

-   add a Virtual Terminal (VT) to your DSN (with its default 9600 Bd, or ..)
-   connect your KBDAT     (Ps2_Data)  pin to the Tx pin of the VT
-   connect your KBCLOCK  (Ps2_Clock) pin to its Rx and CTS pin as in my example projects (see picture).

That's all!
 

Currently the Multi-LCD library is prepared for upload.
zuisti
« Last Edit: May 06, 2013, 09:12:00 09:12 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #4 on: May 06, 2013, 11:54:31 11:54 »

Now my Multi LCD library is presented (rev 0.2  Smiley).

   Simplified (small code) interface for
   - up to two 4bit (6 pins)  LCD,
   - up to two 3wire LCD (using one HC595 shiftreg).

For any PIC16(12) but NOT for enhanced types !!

---------
   Library functions (X: 1 or 2; w3 means 3wire)
  
      LcdX_PinInit()
  w3LcdX_Pins_Init()

(w3)LcdX_Init()

(w3)LcdX_WriteChar(char)
(w3)LcdX_Command(char)
(w3)LcdX_Clear()
(w3)LcdX_Dec2out(char)
(w3)LcdX_Dec3out(char)
(w3)LcdX_Hex2out(char)

(w3)LcdX_RstrOut(char*)
(w3)LcdX_CstrOut(const char*)

(w3)LcdX_GotoYX(char row, char column)     //row: 0-1(nonzero), col: 0-39
           for any LCD but only in the top two rows !!!

(w3)LcdX_Goto4yx16(char row, char column) //row: 0-3, col: 0-15 (for 16x4 !!!)
(w3)LcdX_Goto4yx20(char row, char column) //row: 0-3, col: 0-19 (for 20x4 !!!)
          (A 16x4 LCD to be addressed differently than the 20x4  !!!)


Detailed description in the example C source!

Notes:
- The library can easily expanded to handle more LCD, but I did not see the point.
- I prepared a 2wire LCD version too, but not built into the library, as it is only very rarely, and additional HW elements are needed (a resistor and a diode).

Attached (as usual) the MikroC demo project and DSN. Tried with 4, 8 and 16 MHz PIC clock.
Regards
zuisti

UPDATED (but this 'old' also works):
http://www.sonsivri.to/forum/index.php?topic=52263.msg161461#msg161461
« Last Edit: April 17, 2014, 09:33:10 09:33 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #5 on: May 07, 2013, 11:51:37 11:51 »

The PIC12F683 is one of the most useful 8pin PIC. Available almost everywhere, cheap, 2K Flash, 256 bytes EEPROM, 128 bytes SRAM ...

Unfortunately the COF file (generated by MikroC) is  defective, so the source level debugging does not possible, the  Proteus indicates an error (see the first picture). Of course the simulation is working with the HEX file, when the program is good. However, Proton COF file works fine (see attachment), so Proteus not to blame.

Well, I found a temporary solution to the problem, so we can debug the 12f683 on source level, using the "new" COF file.

    My solution is as follows:

Since we can see that the compiler generates a good (in Proteus usable) COF file using any 16F..., and there is no 16f683 (:-), I made one, so the compiler is "tricked" and generates a well working COF file.

Actually I cloned: simply used the P12F683.c and P12F683.mlk files ( in the "defs" folder), copied them to the same place, but named as P16F683.c and P16F683.mlk. Then inside these UNIX-style text files modified (using a HEX editor) the names from 12f to 16f. The newly created files are included in the RAR so simply copy them to your "defs" folder.

That's it!


Of course, the project settings must be repeated, now using this "new" PIC. Do not forget to set the fuses too (same as before).

If we compare the two COF file (RAR attachment is included both), we can see that the header of the 12f683 COF file is almost empty. I think it's wrong, but that is a matter for developers ...

I tried the above solution with several major 12f683 projects in Proteus, and it works perfectly. Of course, not at all sure that the thing works in the real world, but it is possible because the generated HEX file is the same as it was for the real 12f683 (compared !).

Do not have time for this, but it might be worth checking out the rest 12f... as well (as long as you do not have a final, official patch).

Regards
zuisti
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #6 on: May 08, 2013, 09:01:09 09:01 »

First a note:
  Seems, my previous post (12f683 COF solution) was not helpful to anyone ... never thought  Sad

----------------

If we have more than two output terminals (like in my example) then seems here are a lot of almost
same routine, which can be solved by function pointers, to write a smaller and more elegant C code.

To do this I made the "LIb16_OutUniv.mcl" library file:
    Common output routines using a function pointer to a 'char-out' function
    So far only for the PIC16(12) family
    The pointers may be placed conveniently into an array, as in the example.    


New library functions:
     (and examples, here only with regular MikroC 'char-out' functions,  using only one char parameter)


void CstrOut_Univ(void(*ChOut)(char),const char*);

     example: CstrOut_Univ(Lcd_Chr_CP, "String in the Code memory");
                  CstrOut_Univ(Lcd_Chr_CP, cptr);

void RstrOut_Univ(void(*ChOut)(char),char*);

     example: RstrOut_Univ(UART1_Write, "String in the RAM");

void Hex2out_Univ(void(*ChOut)(char),char);

     example: Hex2out_Univ(UART1_Write, 254);     // writes out: FE (two hex digits)

void Dec2out_Univ(void(*ChOut)(char),char);

     example: Dec2out_Univ(I2C1_Write, 23);        // send '2' then send '3' (0x32 then 0x33)

void Dec3out_Univ(void(*ChOut)(char),char);       // "ddd" (3 decimal digits, max 255)

     example: Dec3out_Univ(Lcd_Chr_CP, 99);       // result: "099"

----------

Prepared (and attached) a slightly more complex example project, using 4 Sw-Uart and 3 LCD at a time.
Its picture is in my first post (in this thread), go here:
http://www.sonsivri.to/forum/index.php?topic=52263.msg150513#msg150513

The project uses (and contains) the previous libraries too;
  the MultiLCD,
  a newer (but absolutely compatible) version of the MultiSwUart,
  and a new 'consolidated' description about them.

Please write your experiences here if you tried these things.

zuisti
PS: now (later  Smiley) already really the PC Keyboard Simulator will be the following ...

UPDATED (but this 'old' also works):
http://www.sonsivri.to/forum/index.php?topic=52263.msg160917#msg160917
« Last Edit: April 17, 2014, 09:38:06 09:38 by zuisti » Logged
Parmin
Hero Member
*****
Offline Offline

Posts: 544

Thank You
-Given: 357
-Receive: 126


Very Wise (and grouchy) Old Man


« Reply #7 on: May 09, 2013, 01:09:31 01:09 »

Your post might be useful Zuisti to some that uses PIC12F683
OTOH, I guess more people are now choosing the newer, cheaper and FASTER 12F1822
I od not use MikroC myself so I can't say if the COFF for F1822 has problem or not.
Logged

If I have said something that offends you, please let me know, so I can say it again later.
zab
Active Member
***
Offline Offline

Posts: 132

Thank You
-Given: 24
-Receive: 54


« Reply #8 on: May 09, 2013, 08:30:20 08:30 »

Hi zuisti
To do this I made the "LIb16_OutUniv.mcl" library file:
It is difficult to see functions name to be called from .mcl files.
if possible can you share these lib file with out compilation in form of .c or .h instead of .mcl so that one can see the codes and adopt them according to specific controller and needs. it would be more helpful to the learners.
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #9 on: May 09, 2013, 10:38:32 10:38 »

Your post might be useful Zuisti to some that uses PIC12F683. I guess more people are now choosing the newer, cheaper and FASTER 12F1822
Yes, and also the 12F1840...

Hi Parmin;
As I wrote above, all my new libraries are working only with  PIC12-PIC16 types (so far, and I'm working on the others like the PIC12/16enh and the PIC18 family). And the 12F683 is more compatible to the well-known 16F types, especially for those who intensive use the inline asm too (like me :-), or at least the FSRPTR - INDF ram accessing mode, which is possible and very useful in MikroC.
-----

"To do this I made the "LIb16_OutUniv.mcl" library file" It is difficult to see functions name to be called from .mcl files.

Hi zab;
I do not really understand why this is difficult. Just as the previous ones, this library also bundled with a description, a working sample code, and even in post # 6 also indicates the callable functions, along with samples.

For example the two-byte HEX output (without any temporaly buffer):
  to the USART
  Hex2out_Univ(UART1_Write, 254);     // send 'FE' (two hex digits)
  to the LCD
  Hex2out_Univ(Lcd_Chr_CP,  254);     // writes 'FE' from the current cursor position
    or, using my 3wire LCD function:
  Hex2out_Univ(w3Lcd1_WriteChar, 254);
and so on, it is working with any 'char-out' function using only one char parameter. It is therefore universal.


Quote
if possible can you share these lib file with out compilation in form of .c or .h instead of .mcl so that one can see the codes and adopt them according to specific controller and needs. it would be more helpful to the learners.

Yes, I understand, but as I wrote (in my post # 0 here), that currently I do not intended to publish the sources of this libraries. Sorry ...

Regards
zuisti
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #10 on: May 09, 2013, 12:08:07 12:08 »

As I wrote above (see post #3) this is not a new Proteus device but a simulation library that can be used
in each PIC12-PIC16 program (without any change !!), which is based on the original MikroC PS2_Library.
Instead, simply the new library must be used, while the original will be omitted, and recompile the project.

It uses the Proteus Virtual Terminal as input device to simulate the PC keyboard inputs (keystrokes).

Big advantage of the MikroC solution (and mine too) is that not interrupt driven, so any two I/O pins can
be used, in fact, the PS2_Data can even an input-only pin (eg GP3 of the 12F683).


 The solution is totally transparent and equal to the original PS2_Library:

   same (only a bit smaller) code-footprint,
   same RAM usage (a bit less too),
   same pin definitions,
   same global variables,
   same functions with same parameters,
   same results (return values);

   so no need to change your software.

   Some minor exceptions, eg not all keys (like WINDOWS) due to the limitations of the Proteus VT.
   Details in the documentation, HW usage also above in post #3:
   http://www.sonsivri.to/forum/index.php?topic=52263.msg150550#msg150550


 I created also two sample projects:

 The first is the simplest Ps2 program from the MikroC PS2 help (its screenshot is also above, in post #3).

 Second, a much more complete project (see the below picture) is a 'real' one-line LCD editor:

   Insert - overwrite mode with different cursor shapes;
   full cursor movement (LEFT-RIGHT via arrow keys, also HOME and END);
   BACKSPACE and DELETE.

All previous sample program is only intended to show how to use the new libraries (like the small programs
in the MikroC help file). However the last, the PS2 Editor's source includes useful details too, I hope.
For those who do not want to use my new LCD library, the program uses just 'official' MikroC LCD functions.


In this way it is possible to use the Proteus source-level debugging too, when a PC (PS/2) keyboard is used.

-----

Please look at also my prev. posts in this thread and write your experiences here if you tried these things.

Thanks,
zuisti

UPDATED (but this 'old' also works):
http://www.sonsivri.to/forum/index.php?topic=52263.msg158269#msg158269
« Last Edit: April 17, 2014, 09:40:52 09:40 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #11 on: July 09, 2013, 05:37:36 17:37 »


This year I gave to my students three programming tasks as the condition of 'graduation'.

They are free to choose from:

-    a 8pin PIC port-expander (24 in and 24 out bits) with an LCD and a remote serial display (see the picture).

-    an RS232 controlled MMD circuit using a 8pin(!) PIC12F683, pixel scroll to left, to right.

-    a PS2 keyboard controlled MMD circuit using a PIC16F628A.

Students may use only the free (2k) mikroC PRO v6, it is also enough. They were provided with all three Proteus projects (hex only), to specify the conditions (the expected properties). Gave and can be used my own libraries (such as the PS2 keyboard Simulator, the multi LCD or the multi SwUart, can be found above in this thread, in binary form).

My basic level PIC programming course is approaching completion, therefore if interested, I can upload the well working Proteus projects (only with HEX firmware, have to understood Smiley), to try writing the program from scratch. Later I'll upload my own complete versions (not the solutions written by my students, since it is their intellectual property).

To inspire here's a screenshot of the first project what can be uploaded even tomorrow if interested. The rest still need to prepare for post, sorry, I'm working on it but only later.

Regards
zuisti
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #12 on: July 10, 2013, 05:00:17 17:00 »


Here's the first task's well working hex-only Proteus project (attached in rar). See my previous post.

Meantime found the pictures of the other two tasks (also attached). Still looking for their DSN and hex files ...
An additional info for the MMD circuits: the scroll speed and direction is also stored in the Pic's Eeprom (used at next power-on).

Greets
zuisti
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #13 on: July 18, 2013, 05:26:46 17:26 »


Here are all three tasks (well working hex-only Proteus projects), attached in rar. See my previous posts in this thread.

The first two task's main problem is of too few (five I/O and one input-only)  PIC pins, but that is why they are also nice jobs.
The easiest task is the third, the PS/2 controlled MMD,"only" should be resolved the timings and to fit into this 2k PIC.

Some additional infos for the MMD circuits:

- the message lenght is min. 70 chars
- 'on the fly' settable the pixel by pixel scroll speed and direction; start-stop control
- the speed and direction is also stored in the Eeprom (used at the next power-on)
- the display refresh rate is min. 70 Hz (8pin, 8MHZ), min. 140 Hz (PS/2, 16 Mhz)

Note:
Also I know it's much easier to use the known custom VLSI circuits (for example the Microchip MCP23017 port-expander IC or the excellent Holtek HT1632C LED display controller/driver chip), and also complete solutions can be found on the net. However, this was not the goal but to learn the program writing from scratch. Therefore students have to write programs only for one of the three given DSN.

Thanks
zuisti (Istvan K.)
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #14 on: September 06, 2013, 01:34:20 13:34 »

Here is the (my) solution of the first task, the 8pinPortExp, see above. The two MMD programs (for some reasons, at request) remain unpublished yet. The full Proteus-only project is attached, the MikroC source too. Note this is just one of the possible solution, try to write your own program for the given DSN if you want.

The program uses the own libraries and (to avoid the 12f683 cof problem) my workaround too. See my previous posts here. The source is not as simple, a bit tricky, try to understand it. Since the Proteus project uses COF (not the hex file), you can debug it also at source level. To build apply pullups for any input switches and use the original MikroC PS2 Library (instead of my KbSim).   
But - sorry - no any 'support', I don't have time now. This is an 'as-is' program.
Good luck.

Thanks
zuisti (Istvan K.)
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #15 on: December 22, 2013, 04:53:41 16:53 »

If anyone still had not found it ...

On the mikroC forum I published some (think) useful routines from my newly prepared libraries, now in pure C language, like:

- Dec_Bcd
- Bcd_Dec

- BcdOut2Uart1
- Dec2Out2Uart1
- BcdOut2Lcd_CP
- Dec2Out2Lcd_CP

- SetLcdPos
- BcdOut2Lcd
- Dec2Out2Lcd

Here you'll find:
http://www.mikroe.com/forum/viewtopic.php?f=88&t=57387
Unfortunately there was no sense of the thing, I do not got any feedback. Maybe here?

Rgds
zuisti

Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #16 on: January 02, 2014, 10:13:44 10:13 »

** UPDATED ** (02.01.2014, Happy New Year).

Now separated libraries for the three PIC families (pic12/16,  pic12/16_Enh  and  pic18).
Heavily hand-optimized for speed, and to minimize the code size, stack and ram usage.
The Ps2_Key_Read_ND (no keyname display) function is also added for time-critical applications.
In the attached RAR the description and the example projects are also actualized. 

zuisti
PS:
I would like to receive feedback!
Logged
Vineyards
Active Member
***
Offline Offline

Posts: 130

Thank You
-Given: 36
-Receive: 25


« Reply #17 on: January 02, 2014, 12:24:52 12:24 »

Zuisti you have always been a very helpful member. Of course, your knowledge and experience make this possible.
I am mostly working with Pic18 series and have to write hefty code. I am virtually ignorant when it comes to ASM.
Does PIC18 series require a lot of alteration in your code? Do you have to rewrite the whole thing if you want to adapt it to another PIC version in the same family?
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #18 on: January 02, 2014, 01:20:28 13:20 »

Does PIC18 series require a lot of alteration in your code? Do you have to rewrite the whole thing if you want to adapt it to another PIC version in the same family?
From the same family any PIC can be used. For example, my "p18_KbSim.mcl" library is good for any PIC18..., only properly have to define the port pins (like anyway also, look at my demo projects).

While you are using only pure C instructions (no inline asm) in your program, do not worry about the different PICs, the compiler knows, what it must to do. Only the project properly have to set.
« Last Edit: January 02, 2014, 01:30:28 13:30 by zuisti » Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #19 on: January 02, 2014, 04:45:57 16:45 »

I would like to comment, but:

1. I do not use MikroC
2. I can't see the code as it is in library form
3. I have no proteus installed on my pc anymore

The only comment is from the description: isn't that more common to convert numbers to string then kicking it out by a kind of string out function?

-ichan
Logged

There is Gray, not only Black or White.
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #20 on: January 02, 2014, 06:02:22 18:02 »

Thanks Ichan for your comments.

I would like to comment, but:
1. I do not use MikroC
In this case my libraries and other codes are really worthless for you (but see the title of this topic).

Quote
2. I can't see the code as it is in library form
Yes, but I think there is no point to publish the in asm written sources (see below).

Quote
3. I have no proteus installed on my pc anymore
My answer is the same as for your first comment: the Keyboard Simulator is working only in Proteus (since therefore made), it is also worthless for you.

Quote
... isn't that more common to convert numbers to string then kicking it out by a kind of string out function?
It may be more common, but sure it uses more ram (and stack depth), much slower and much longer in final code compared to the heavily optimized, almost full (family-specific) inline asm functions, which written by me, first only for private use, now I published them to use others too. Sorry.
« Last Edit: January 02, 2014, 06:04:29 18:04 by zuisti » Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #21 on: January 02, 2014, 08:32:18 20:32 »

Hi Zuisti,

I have no negative intention on my previous post.

Your works are great, i was trying to say that i think you may not get many feedback as there are only small audience for it, people may download it but then says "it's not for me".

Many people (me for sure) will choose the easy ways to use more common approach, while moving to a larger capacity and more powerful  mcu is dirt cheap these days.

Cheers.

-ichan
Logged

There is Gray, not only Black or White.
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #22 on: January 27, 2014, 05:38:10 17:38 »

Two variants: high (80 pts) and low (48 pts) resolution.
Heavily hand-optimized for speed, and to minimize the code size, stack and ram usage.

The library contains two functions to create 16char wide bargraph(s):

void Bargraph_Init(void);

-    to create bargraph UD chars (2-7), 0 and 1 are free (empty),
-    and also 2,3,4 can be used (redefined) if no HiRes (see below).
-    It is small and fast (no any const char array).

void Bargraph(char HiRes, unsigned value);

-    value: 0 - 1023; if HiRes != 0 then 80pts else 48pts:
-    overrun protected: if value > 1023 then it displays 1023
-    always prints 16 chars (from the current cursor position !!)
-    Extremely fast and small (only 8bit arithmetics).
-    Resolution dependent proportional division with rounding.

-----

Separated libraries for the three families (pic12/16, pic12/16_Enh and pic18):
    there are three library prefixes:
    p16_    p16e_     p18_   
eg for a PIC16F1847 use the "p16e_Bargraph_MeLCD.mcl".

The "_MeLCD" postfix means that it uses (calls) two MikroE LCD libary functions:
     extern void Lcd_Cmd(char);
      extern void Lcd_Chr_CP(char);

However, you can write your own functions too :-) but use the same names.

The attached RAR contains demo projects too.

An improved, expanded version is also uploaded (but this 'old' also works):
http://www.sonsivri.to/forum/index.php?topic=52263.msg160361#msg160361
« Last Edit: April 17, 2014, 09:48:10 09:48 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #23 on: March 08, 2014, 12:24:30 00:24 »

            NEW,  ALL-IN-ONE

The library contains a function which allows to create parameterized bargraph(s) on an HD44780 compliant LCD.

-    Scalable, configurable via predefined mode constants.
-    Any width can be used, it's limited by the LCD line lenght only !!
-    8 different mode (variants): 3-5-7 segments and 35 pixels, all twice.
-    No any init function since the used custom char is on the fly defined
-    Max. 8 independent (even 1..4 char vertical) bargraph can be used on
          the same LCD (because there are only 8 custom chars).

Separated libraries for the three families (pic12/16, pic12/16_Enh and pic18).


     USAGE:

LCD_BarGraph(char cc,                     used custom char (0...7), must be unique !!
                       char pos,                   starting position, eg _LCD_THIRD_ROW + 3
                       char mode,                variant (use one of the predefined constants)
                       char width,                 number of chars, determines the full-scale
                       unsigned value);         will be displayed

The "LCD_" tag means that it uses (calls) two mikroE LCD libary functions:

      extern void Lcd_Cmd(char);
      extern void Lcd_Chr_CP(char);

and you have to use the usual LCD pin definitions and the Lcd_Init func
      (but you can write your own functions too, using the same names).


Animation shows how to operate the different modes:

       

Four different 14ch horizontal, three different 4char vertical Bargraph, full scale = 1024 counts:

       

I created several Proteus projects (attached with C sources) to show the possibilities.
The circuit is always the same, the "8chVoltmeter_4v9.DSN":

     

The outputs of the specific demo programs:

     
 
Enjoy (see attached)!
zuisti
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #24 on: March 15, 2014, 11:39:51 11:39 »

Upon request, I created an improved variant (add to my BarGraph library DEMO programs):

-  SW filtering:   four measurings/channel then average value will be calculated but only
   when it detects a difference compared to the previous (stored) average value, else the
   fast scanning (appr 9 ms / 8 channels) will be continued.
    - an improved 50 Hz noise suppression also can be used (with appropriate delays)

-  on the fly switchable high-res (pixel) bargraphs, now with rounded voltages
   and channel-number displaying (not the best but the space is limited)
 

   As before:

-  no floating arithmetics (fast)

-  small code (my all-in-one BarGraph function is only 213 bytes long on a P16)

-  full scale = Vref (VCC, now 4.9 V), with SW correction: see the docs.

-  resolution = 0.001 V (but 0.01 V with bargraph, after rounding)

-  accuracy   = +-0.1% (max 5 mV), plus the PIC's own ADC error, of course :-)
 

The entire mikroC project is attached, with the C source (detailed comments) and the DSN file. In Proteus (I tested only here !) it uses the COF compiler output so a source-level step-by-step debugging is also possible.

The pictures show the simulated circuit and the bargraph displaying (same input voltages).

zuisti
« Last Edit: March 15, 2014, 12:47:02 12:47 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