Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 21, 2024, 09:42:19 09:42


Login with username, password and session length


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

Posts: 409

Thank You
-Given: 242
-Receive: 780


« on: May 05, 2013, 11:18:28 11: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, 11:21:39 11:21 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #1 on: May 05, 2013, 03:43:26 15: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: November 04, 2017, 12:07:21 00:07 by pickit2 » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #2 on: May 06, 2013, 07:57:43 07: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: November 04, 2017, 12:08:29 00:08 by pickit2 » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #3 on: May 06, 2013, 10:54:31 10: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: November 03, 2017, 11:58:42 23:58 by pickit2 » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #4 on: May 07, 2013, 10:51:37 10: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
« Last Edit: November 04, 2017, 12:00:21 00:00 by pickit2 » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #5 on: May 08, 2013, 08:01:09 08: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: November 04, 2017, 12:11:02 00:11 by pickit2 » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #6 on: May 09, 2013, 09:38:32 09: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
« Last Edit: November 04, 2017, 01:59:09 13:59 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #7 on: May 09, 2013, 11:08:07 11: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: November 04, 2017, 01:38:02 13:38 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #8 on: July 09, 2013, 04:37:36 16: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
« Last Edit: November 04, 2017, 01:40:04 13:40 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #9 on: July 10, 2013, 04:00:17 16: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
« Last Edit: November 04, 2017, 01:44:40 13:44 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #10 on: July 18, 2013, 04:26:46 16: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.)
« Last Edit: November 04, 2017, 01:47:57 13:47 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #11 on: September 06, 2013, 12:34:20 12: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.)
« Last Edit: November 04, 2017, 12:19:37 00:19 by pickit2 » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #12 on: December 22, 2013, 03:53:41 15: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

« Last Edit: November 04, 2017, 12:20:40 00:20 by pickit2 » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


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

** UPDATED Ps2 simulator library ** (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!
« Last Edit: November 04, 2017, 01:51:00 13:51 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #14 on: January 02, 2014, 12:20:28 12: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: November 04, 2017, 01:54:08 13:54 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #15 on: January 02, 2014, 05:02:22 17: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: November 04, 2017, 01:57:42 13:57 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #16 on: January 27, 2014, 04:38:10 16: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: November 04, 2017, 12:32:55 00:32 by pickit2 » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #17 on: March 07, 2014, 11:24:30 23:24 »

            NEW,  ALL-IN-ONE Bargraph library

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
« Last Edit: November 04, 2017, 05:01:49 17:01 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #18 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: November 04, 2017, 05:05:41 17:05 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #19 on: March 25, 2014, 12:20:19 12:20 »

There are 12 routines ("..." is the distinctive prefix, see below):

Code:
   String output:

...RstrOut (char* rptr)               //write out a string stored in Ram
...RstrNout(char* rptr, char N)       // the same but max N char(s)
...CstrOut (const char* cptr)         //write out a string stored in Code memory
...CstrNout(const char* cptr, char N) // the same but max N char(s)


   Direct conversion (without any temporary buffer):

...BcdOut (char)     //  "dd", char: max 0x99 (153), with leading zero(es)
...Dec2out(char)     //  "dd", char: max 99,                  -"-
...Hex2out(char)     //  "hh", char: max 255,                 -"-
...Hex4out(unsigned) //  "hhhh", max 65535,                   -"-

       Justified direct conversion
       (controlled by an additional "just" parameter):

       just = -1: (ie just.B7 = 1) no alignment (with leading zeroes)
       just =  0: leading zeroes will be supressed (left  justified)
       just =  1: leading zeroes will be a space   (right justified)

...Dec2out_J(char onebyte, char just) //    "dd" (or "d" or " d"), max 99 !!
...Dec3out_J(unsigned wrd, char just) //   "ddd", max 999
...Dec4out_J(unsigned wrd, char just) //  "dddd", max 9999
...Dec5out_J(unsigned wrd, char just) // "ddddd", max 65535

See the "COMMONFUNCS_DOC.H"

These heavily optimized (using family-specific inline ASM) functions are included in my two new libraries (presented now):

   "p*_UART1-LCDouts.mcl"
       prefixes: "UART1_" and "LCD_"    (see the "UART1-LCD-DOC.H")

   "p*_Out_Univ.mcl"
       prefixes: "Ptr_" and "Usr_"           (see the "OUT_UNIV_DOC.H")

For all 8-bit PICs, using different library prefixes (p*):

    p16   : PIC 12/16 (non-enhanced) family
    p16e : PIC 12/16  enhanced family
    p18   : PIC 18       family

For example use the "p18_UART1-LCDouts.mcl" for any PIC18 chip.
« Last Edit: November 04, 2017, 12:37:26 00:37 by pickit2 » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #20 on: April 13, 2014, 03:21:38 15:21 »

This is the third part of my new library collection (the already published parts are the "Bargraph",
"PS2 Keyboard Simulator" and the "Common output functions").

Same way usable (uniformized) LCD libraries. Every precompiled lib allows you to manage up to
four HD44780 compliant LCD. For all 8-bit PIC.

"..Lcd" prefix is used to distinct the type of the interface:
     where ".." may be: (none)  B  w3  w2  w1  N8  B8  (eg p16e_w2Lcd-4.mcl)

  1.     Lcd      the usual nybble (4-bit) interface (most used)
  2.   BLcd      the same but with Busy flag checking (faster)

          using HC595 as a port expander (3 separated libraries):

  3. w3Lcd     3-wire interface
  4. w2Lcd     2-wire
  5. w1Lcd     1-wire

  6. N8Lcd     the normal full (8-bit) interface (smallest code)
  7. B8Lcd     the same but with Busy flag checking

So there are seven different library (sum 7 * 3 = 21 "p*_....-4.mcl" file, in
accordance of the three different PIC family; p* = p16, p16e or p18).

Every library contains 6 'fundamental' functions for the four (0...3) LCD:
   Init - WriteChar - Command - UserChar - GotoYX - GotoYX_16x4
using a specific, library-dependent prefix (eg w1LcdX_Init, where X = 0..3)

In addition, they contain the 12 'common output' functions for the ..Lcd0:
   CstrOut - CstrNout - RstrOut - RstrNout - Hex2out - Hex4out
   BcdOut - Dec2out - Dec2out_J - Dec3out_J - Dec4out_J - Dec5out_J

Detailed description in the "LCD-libs_DOC.H".
A demo project is included to show the 1-, 2- and 3-wire interface circuits.
« Last Edit: November 04, 2017, 05:07:37 17:07 by zuisti » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #21 on: April 16, 2014, 03:56:57 15:56 »

This is a newest member of my new, same way usable (uniformized) library collection
  (the already published parts are the "Bargraph", the "PS2 Keyboard Simulator",
  the "Common outputs" and the "Full LCD" libraries).

SwUart library v3.0.

Improved, expanded but almost full downward compatible version.

Allows you to handle 4 independent software (bit-banging) Uart.

Now also for all 8-bit PIC (pic12/16, pic12e/16e and pic18), so it is three different library
("p*_SwUart-4.mcl" file), in accordance of the three different PIC family; p* = p16, p16e or p18.

The library contains  5  'fundamental'  functions  for the four  (0...3)  Sw Uart:
   InitW - InitT - Write - ReadW - ReadT (now also 'zero' char too !!)
using the specific prefix "SUartX_", where X = 0...3

In addition, it contains the 12 'common output' functions for the "SUart0":
   CstrOut - CstrNout - RstrOut - RstrNout - Hex2out - Hex4out
   BcdOut - Dec2out - Dec2out_J - Dec3out_J - Dec4out_J - Dec5out_J

Detailed description in the "SWUART_DOC.H". A demo project is also included.

Istvan K. (zuisti)
« Last Edit: November 04, 2017, 12:39:28 00:39 by pickit2 » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #22 on: April 25, 2014, 04:50:58 16:50 »

Memory manipulation function set. In addition, some simplified arithmetic
and bit-handling routines. All in one library named as "p*_Mem-Arithm.mcl".
For all 8-bit PIC  (pic12/16, pic12e/16e and pic18): p* = p16, p16e or p18.

My goal was to create some simplified routines (not so universal but much smaller
and faster as the official libraries) to manipulate strings, bits and memory.

Optimized for speed, and to minimize the size, stack and ram usage.
Very often used (family-specific) inline asm codes too.

The library contains a total of 45 function:

  sprint-like common output routines. S..., Si... (string insert): no end sign:

SHex2 - SiHex2 - SHex4 - SiHex4 - SBcd - SiBcd - SDec2 - SiDec2 - SDec2_J
SiDec2_J - SDec3_J - SiDec3_J - SDec4_J - SiDec4_J - SDec5_J - SiDec5_J

  string lenght (max 255):

RstrLen - CstrLen
  
  string manipulations:

SpaceStr - iSpaces - AllSpaces - iChr - ChrApp - LefTrim - RighTrim

  string/memory copying (from RAM to RAM):

RstrIns - RstrNins - RstrCpy - RstrNcpy - RstrApp - RstrNapp - RmemCpy

  const string/code memory copying (to RAM):

CstrIns - CstrNins - CstrCpy - CstrNcpy - CstrApp - CstrNapp - CmemCpy

  in addition, 4 simple 8-bit arithmetic functions:

Dec_Bcd - Bcd_Dec - DivMod10 - MiniMul_10

  and two bitmask functions (for the attached "pic_BitMacros.h"):

R2BitMask - R2BitMaskW

------

Just for example, the 16e "LefTrim" function is 5.39 times faster (64 vs 341 cycles)
and 2.9 times smaller (21 vs 61 bytes) than the original "Ltrim" routine, while working
on the same, 8 chars lenght string with 5 leading blanks.

Detailed description and some example in the "MEM-ARITHM_DOC.H"
Istvan K. (zuisti)
« Last Edit: November 04, 2017, 12:42:02 00:42 by pickit2 » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #23 on: September 25, 2014, 11:02:24 11:02 »

Special request I made (and now publish) this 'simple' MMD.

- 67.5 Hz refresh rate at 40 MHz clock (in ISIS 30.4 Hz to avoid display flickers).
- 4 in 1: handles four independent char-lines (fix texts), common run/stop key.
  (using a timed state machine with six different phase)
- A bit tricky addressing of the two 4_to_16 demultiplexers (2 * hc154).
- Written in pure C, resizable and easily portable, verbose comments.
- Works with my 'good old' row-scanning algorithms.
- also detailed shows how to calculate the timings (using timer2)
  to get always the same brightness (switched on time) for every row.

Attached the complete mikroC project (with all sources) and also the
Proteus DSN file (it uses COF so the program is step-by-step debuggable).

 Tried only in Proteus !!

zuisti (Istvan K.)
« Last Edit: November 04, 2017, 12:42:34 00:42 by pickit2 » Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #24 on: June 12, 2015, 11:09:26 11:09 »

Code:
char GetParity(char ch) {
R0 = ch;
asm {
  swapf R0, W
  xorwf R0, F
  #ifndef P18   // ie each P12, P16 and P16 enhanced
    rrf R0, W
  #else
    rrcf R0, W  // the mnemonic is different  in P18 !!!
  #endif
  xorwf R0, F
  btfsc R0, 2
  incf R0, F
  movlw 1
  andwf R0, F
}
return R0;      // there 1 means ODD and 0 means EVEN parity
}
« Last Edit: November 04, 2017, 05:12:23 17:12 by zuisti » Logged
Pages: [1] 2 3  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