AVR Microbasic TFT ILI9325 LCD Proteus simulation - basic

If anyone worked with Nokia N96 LCD Display with ILI9325 Display controller, please let me knew.
I am writing Basic code that helps display a character on the screen. The screen is 320 by 240 pixel matrix. The controller provides a GRAM(Graphics RAM) memory where in we write the data to display corresponding character.
I Found the Proteus library for TFT ILI9325 form this link:
dll file of ILI9325 GLCD for proteus
and
Proteus simulation on bascom
And so when i want to change it to mirobasic software with below code,LCD don't show anything!!!
The Microbasic Codes based of ILI9325 datasheet:
program MyProject
'*******************************************************************************
'----- Color LCD CONFIG --------------------------------------------------------
'*******************************************************************************
dim Back_light as sbit at Portg0_bit
dim Color_lcd_cs as sbit at Porta3_bit
dim Color_lcd_rs as sbit at PORTa0_bit
dim Color_lcd_wr as sbit at PORTa1_bit
dim Color_lcd_rd as sbit at PORTa2_bit
dim Color_lcd_rst as sbit at PORTa4_bit
dim Color_lcd_lsb_port as byte at PORTD ' this is where PORTAlias is fully defined
dim Color_lcd_msb_port as byte at PORTE ' this is where PORTAlias is fully defined
Dim Entry_mod As Word 'Horizantal=&H1028,Vertical=&H1030
Dim Color_lcd_index As Byte 'Index Variable
Dim Color_lcd_data As Word 'Data Variable
Dim Lcd_buff As String [ 25]
Dim xX As Word
Dim Yy As Word
Dim O As Word
Dim X_c As Word
Dim Y_c As Word
'*******************************************************************************
'*******************************************************************************
'----- COLOR LCD SUBROUTINES ---------------------------------------------------
'*******************************************************************************
'*******************************************************************************
Sub procedure Triger_color_lcd()
Color_lcd_rst=0
delay_ms( 60)
Color_lcd_rst=1
delay_ms( 200)Color_lcd_index = 0xE3 '' Write_color_lcd_index
Color_lcd_data = 0x3008 '' Write_color_lcd_data
Color_lcd_index = 0x00E7 '' Write_color_lcd_index
Color_lcd_data = 0x0000 '' Write_color_lcd_data
End Sub
Sub procedure Write_color_lcd_index()
Color_lcd_cs=0
Color_lcd_rs=0
Color_lcd_rd=1
Color_lcd_msb_port = 0x00
Color_lcd_lsb_port = Color_lcd_index
Color_lcd_wr=0
Color_lcd_wr=1
Color_lcd_cs=1
End Sub
Sub procedure Write_color_lcd_data()
Color_lcd_cs=0
Color_lcd_rs=1
Color_lcd_rd=1
Color_lcd_msb_port = Hi(color_lcd_data)
Color_lcd_lsb_port = Lo(color_lcd_data)
Color_lcd_wr=
Color_lcd_wr=1
Color_lcd_cs=1
end sub
'*******************************************************************************
main:
Color_lcd_index = 0x13 '' Write_color_lcd_index
Color_lcd_data = 0x1111 '' Write_color_lcd_data
Write_color_lcd_index()
Write_color_lcd_data()
while True
wend
' Main program
end.
the code with Proteus is [Here]:
www.filepi.com/i/1pnpxUD
and the result is the same as this picture:
www.i.stack.imgur.com/7xsR2.jpg

No answer!!!
So i found the proper answer and proper codes with MikroC for AVR here:
main.c:
//================================ LCD CONFIGURATIONS =======================================
#define PORTRAIT
#define LCD_CONTROLPORT_DDR DDRA
#define LCD_CONTROLPORT_PORT PORTA
#define LCD_CONTROLPORT_PIN PINA
#define LCD_RST_DDR DDRA
#define LCD_RST_PORT PORTA
#define LCD_RST_PIN 4
#define LCD_RS_DDR DDRA
#define LCD_RS_PORT PORTA
#define LCD_RS_PIN 0
#define LCD_CS_DDR DDRA
#define LCD_CS_PORT PORTA
#define LCD_CS_PIN 3
#define LCD_RD_DDR DDRA
#define LCD_RD_PORT PORTA
#define LCD_RD_PIN 2
#define LCD_WR_DDR DDRA
#define LCD_WR_PORT PORTA
#define LCD_WR_PIN 1
#define LCD_DATAPORT_MSB_DDR DDRE
#define LCD_DATAPORT_MSB_PORT PORTE
#define LCD_DATAPORT_MSB_PIN PINE
#define LCD_DATAPORT_LSB_DDR DDRD
#define LCD_DATAPORT_LSB_PORT PORTD
#define LCD_DATAPORT_LSB_PIN PIND
//================================================================
#include "tftlcd_functions.h"
void main(void)
{
lcd_init();
// lcd_background_color(GREEN);
while (1)
{
lcd_gotoxy(11,11);
lcd_putsf(" TFT LCD 2.8' ",0x0000,0,RED);
lcd_gotoxy(11,11);
lcd_putsf(" www.Elasa.ir ",0x0000,0,BLUE);
Delay_ms(200);
lcd_clear_screen();
lcd_background_color(BLACK);
lcd_draw_line(5,5,50,50,0xFFFF);
lcd_draw_rectangle(30,30,80,80,0,0XFFFF);
lcd_draw_circle(150,150,25,0,0xffff);
Delay_ms(200);
}
}
Proteus Simulation
and the other files with Proteus simulation in this file:
http://filepi.com/i/VlZM9PN
Files for Download
sincerely yours:
Soheil sabz

Related

using the FMU in fmu_sdk

I have a small code in C that I want to use to call the IMF functions of fmu_sdk in order to be able to export my model in FMU.
If you could tell me how the functions I need to use, here is my program:
best regards
Mary
Do you want to create a model exchange or co-simulation FMU?
Here is a link to a model-exchange FMU that implements an AND for two boolean input values (FMI 2.0, win64): https://www.dropbox.com/s/su8pyjdtg4hs7v1/fmu_boolRef.fmu?dl=0
And here a link to a co-simulation FMU: https://www.dropbox.com/s/bcbl8tf6xb4jc8x/fmu_boolRef.fmu?dl=0
You can compile the the contained source code also to a co-simulation FMU.
#include <stdio.h>
#include <stdlib.h>
#define vrai 1
#define faux 0
typedef enum BOOLEAN {false, true} bool;
bool function_ET(bool e1,bool e2);
int main(){
bool e1;
bool e2;
bool s;
printf("entrez les valeur de e1 et e2:");
scanf("%d%d",&e1 ,&e2);
s = function_ET(e1,e2);
printf("s = %d",s);
}
bool function_ET(bool e1,bool e2){
return(e1 & e2);
}
I was able to write the code C, but I did not manage to have the good result, I can not increment the values of e1 and e2, the values do not change with time, if you could m Help you write the exact code
#define MODEL_IDENTIFIER prog_entree1
#define MODEL_GUID "{8c4e810f-3da3-4a00-8276-176fa3c9f013}"
// define model size
#define NUMBER_OF_REALS 0
#define NUMBER_OF_INTEGERS 0
#define NUMBER_OF_BOOLEANS 3
#define NUMBER_OF_STRINGS 0
#define NUMBER_OF_STATES 0
#define NUMBER_OF_EVENT_INDICATORS 0
// include fmu header files, typedefs and macros
#include "fmuTemplate.h"
//#include "prog1entrée.c"
#define e1 0
#define e2 1
#define s_ 2
void setStartValues(ModelInstance *comp) {
b(e1) = 1;
b(e2) = 0;
}
void calculateValues(ModelInstance *comp) {
if (comp->state == modelInitializationMode) {
b(s_)= b(e1) && b(e2);
}
}
fmi2Boolean getBoolean(ModelInstance* comp, fmi2ValueReference vr)
{
switch(vr)
{
case e1 : return b(e1);
case e2 : return b(e2);
case s_ : return b(s_);
}
}
void eventUpdate(ModelInstance *comp, fmi2EventInfo *eventInfo, int
timeEvent, int isNewEventIteration)
{
}
// include code that implements the FMI based on the above definitions
#include "fmuTemplate.c"
And the result I got after the simulation
enter image description here

Compiles fine with g++ but fails with Visual Studio 2015

I have a perplexing problem with Visual Studio 2015, C++, macros. I do have a bigger project at the background, but the following toy example illustrates the problem.
I have the following C++ code (oma8.rc, oma8.h, oma8.cpp) to create a toy dialog. It compiles with gcc compiler nicely:
windres -O coff -i oma8.rc -o oma8.res
g++ oma8.cpp oma8.res -o oma8
// oma8.cpp
#include <windows.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <stdio.h>
#include "stdlib.h"
#include "oma8.h"
using namespace std;
string param2;
int b1, b3;
string GetInputText( HWND dlg, int resid ) {
HWND hc = GetDlgItem( dlg, resid );
int n = GetWindowTextLength( hc ) + 1;
string s( n, 0 );
GetWindowText( hc, &s[0], n );
return s;
}
int GetCheck( HWND dlg, int resid) {
HWND hc = GetDlgItem(dlg,resid);
int n = IsDlgButtonChecked( dlg, resid);
return n;
}
BOOL CALLBACK DialogProc( HWND hwnd, UINT message,
WPARAM wp, LPARAM ) {
switch ( message ) {
case WM_COMMAND: {
int ctrl = LOWORD( wp );
int event = HIWORD( wp );
if ( ctrl == IDCANCEL && event == BN_CLICKED ) {
DestroyWindow (hwnd);
return TRUE;
}
else if ( ctrl == IDOK && event == BN_CLICKED ) {
param2 = GetInputText( hwnd, IDC_EDIT1 );
b1 = GetCheck( hwnd, RB1 );
b3 = GetCheck( hwnd, RB3 ); // ignore the other buttons for now
DestroyWindow (hwnd);
return TRUE;
}
return FALSE;
}
case WM_DESTROY:
PostQuitMessage(0);
return TRUE;
case WM_CLOSE:
DestroyWindow (hwnd);
return TRUE;
}
return FALSE;
}
int main() {
HWND dlg = CreateDialog( GetModuleHandle(0),
MAKEINTRESOURCE( IDD_DIALOG1 ),
0, DialogProc );
MSG msg;
while ( GetMessage( & msg, 0, 0, 0 ) ) {
if ( ! IsDialogMessage( dlg, & msg ) ) {
TranslateMessage( & msg );
DispatchMessage( & msg );
}
}
cout << "corner text: " << param2 << " as a number: " << atof(&param2[0]) << endl;
cout << "radio1: " << b1 << " radio3: " << b3 << endl;
}
// oma8.rc (stripped 3 comment lines from start)
#include <windows.h>
#include "oma8.h"
//#include "winresrc.h" // apparently not needed
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG1 DIALOG 20, 20, TABNR(8), THISLINEHEIGHT(15)
STYLE DS_3DLOOK | DS_SETFONT | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_SIZEBOX
//STYLE DS_CENTER | DS_SHELLFONT | DS_FIXEDSYS | DS_MODALFRAME | WS_VSCROLL | WS_POPUP
CAPTION "Caption here"
FONT 10, "Arial"
{
LTEXT "Corner text",IDC_STATIC,LMARG,UPMARG,60,RHEIGHT
EDITTEXT IDC_EDIT1, 60, UPMARG, 60,FIELDH, ES_AUTOHSCROLL
DEFPUSHBUTTON "OK",IDOK,TABNR(5),UPMARG,TABW,FIELDH
PUSHBUTTON "Cancel",IDCANCEL,TABNR(6),UPMARG,TABW,FIELDH
LTEXT "Block1, line 1",IDC_STATIC,TABNR(RBCOLUMN),THISLINEHEIGHT(PARAMLINE),TEXTW,RHEIGHT
AUTORADIOBUTTON "B1, line 2",RB1,TABNR(RBCOLUMN),THISLINEHEIGHT(PARAMLINE+1),TEXTW,RHEIGHT,WS_GROUP
AUTORADIOBUTTON "B1, line 3",RB2,TABNR(RBCOLUMN),THISLINEHEIGHT(PARAMLINE+2),TEXTW,RHEIGHT
LTEXT "Block2 col 1",IDC_STATIC,TABNR(SNGLCOLUMN),THISLINEHEIGHT(CHOICELINE),TABW,RHEIGHT
AUTORADIOBUTTON "B2 col 2",RB3,TABNR(SNGLCOLUMN+1),THISLINEHEIGHT(CHOICELINE),TABW,RHEIGHT, WS_GROUP
AUTORADIOBUTTON "B2 col 3",RB4,TABNR(SNGLCOLUMN+2),THISLINEHEIGHT(CHOICELINE),TABW,RHEIGHT
LTEXT "Block3, line 1",IDC_STATIC,TABNR(RANGECOLUMN),THISLINEHEIGHT(TXLINE),TEXTW,RHEIGHT
AUTORADIOBUTTON "B3, line 2",RB5,TABNR(RANGECOLUMN),THISLINEHEIGHT(RXLINE),TEXTW,RHEIGHT,WS_GROUP
AUTORADIOBUTTON "B3, line 3",RB6,TABNR(RANGECOLUMN),THISLINEHEIGHT(SCLINE),TEXTW,RHEIGHT
}
// oma8.h (stripped 2 comment lines from start)
#define IDD_DIALOG1 100
// basic buttons
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif
#ifndef IDOK
#define IDOK 40000
#endif
#ifndef IDCANCEL
#define IDCANCEL 40001
#endif
// measures
#define LMARG 6
#define UPMARG 5
#define TEXTW 120 // rb text width
#define TABW 50 // tab width
#define FIELDW 30 // fill-in field w
#define FIELDH 13 // fill-in field h
#define RHEIGHT 14 // row height
// line numbers
#define PARAMLINE 2
#define NOFPARAMS 2
#define OFFSET2 2
#define OFFSET3 5
#define CHOICELINE (PARAMLINE+NOFPARAMS+OFFSET2)
#define TXLINE (CHOICELINE+1)
#define RXLINE (CHOICELINE+2)
#define SCLINE (CHOICELINE+3)
#define RANGETITLELINE 2
#define RANGEFIELDLINE (RANGETITLELINE+1)
#define DETECTORLINE (CHOICELINE+OFFSET3)
#define THISLINEHEIGHT(x) (UPMARG+(x)*RHEIGHT)
// column numbers
#define TABNR(x) (LMARG+TABW*(x))
#define RBCOLUMN 1
#define RANGECOLUMN 5
#define SNGLCOLUMN 2
#define DTCTCOLUMN 7
// parameter buttons
#define IDC_EDIT1 1002
#define RB1 1010
#define RB2 1011
#define RB3 1012
#define RB4 1013
#define RB5 1014
#define RB6 1015
and oma8.exe (all commands given in a console) opens a dialog that looks exactly as I want it to, hooray. But, I have reasons that I must compile this also with VS2015. (It will be later inserted into a certain boilerplate code, but that's not relevant here.)
When trying to compile the same code with VS2015, I get a bunch of error messages related to the .rc file, especially on its macro functions. The first 4 are
Error RC2112 BEGIN expected in dialog oma8.rc 11
Error RC2135 file not found: 0x00040000L oma8.rc 12
Error RC2135 file not found: here oma8.rc 14
Error RC2135 file not found: 10 oma8.rc 15
Furthermore, if I change the lines
#define THISLINEHEIGHT(x) (UPMARG+(x)*RHEIGHT)
#define TABNR(x) (LMARG+TABW*(x))
into
#define THISLINEHEIGHT(x) (UPMARG + (x) * RHEIGHT)
#define TABNR(x) (LMARG + TABW * (x))
I get just one error message:
Error RC2104 undefined keyword or key name: * oma8.rc 11
I must have something funny with my linker/compiler options? When creating this as a Project From Existing Code, I chose Console App and left all other choices as defaults. (Can't remember what those were, sorry, just lots of acronyms.)
I've spent over a week googling and trying different modifications, but haven't been able to fix this. I don't know what else to try. Where should I look into? Any ideas and further questions would be welcome.
My system is Win7, 64-bit. g++ version says g++ (tdm-1) 5.1.0 (C) 2015 Free Software Foundation Inc.

How to concatenate number to string in macro?

I want to concatinate a version number to a string in inno-setup preprocessor macros. I tried to use the stringer trick (used in c++ macros) like this:
#define stringer_helper(arg) #arg
#define stringer(arg) stringer_helper(arg)
#define version 1
#define myapp "lala " + stringer(version)
but get the error:
Illegal character in input file: '#' (0x23)
How is it possible to append a number define to a string define?
You can use the Str function to typecast your integer variable:
#define MyString "Text"
#define MyInteger 666
#define MyVariable MyString + Str(MyInteger)

Linux kernel 0.0.1 vs 2.6.36, "ctype.h", whats the difference?

How efficient is linux kernel 2.6.36 from 0.0.1
0.0.1:
I understand, in this version, Linus has assigned the value of
c(input variable to a function) to a temp variable and operate on
that temp variable inside the function and return the temp variable.
This happens in tolower/toupper functions.
2.6.36:
Here in tolower/toupper he changed it.
ctype is const.
New function ismask is written.
What I want to know?:
Why these changes has been made?, what good it brought home?
I have listed out the ctype.h files in the kernel versions of 0.0.1 and 2.6.36, respectively.
**** ctype.h, linux-0.01 *****
#ifndef _CTYPE_H
#define _CTYPE_H
#define _U 0x01 /* upper */
#define _L 0x02 /* lower */
#define _D 0x04 /* digit */
#define _C 0x08 /* cntrl */
#define _P 0x10 /* punct */
#define _S 0x20 /* white space (space/lf/tab) */
#define _X 0x40 /* hex digit */
#define _SP 0x80 /* hard space (0x20) */
extern unsigned char _ctype[];
extern char _ctmp;
#define isalnum(c) ((_ctype+1)[c]&(_U|_L|_D))
#define isalpha(c) ((_ctype+1)[c]&(_U|_L))
#define iscntrl(c) ((_ctype+1)[c]&(_C))
#define isdigit(c) ((_ctype+1)[c]&(_D))
#define isgraph(c) ((_ctype+1)[c]&(_P|_U|_L|_D))
#define islower(c) ((_ctype+1)[c]&(_L))
#define isprint(c) ((_ctype+1)[c]&(_P|_U|_L|_D|_SP))
#define ispunct(c) ((_ctype+1)[c]&(_P))
#define isspace(c) ((_ctype+1)[c]&(_S))
#define isupper(c) ((_ctype+1)[c]&(_U))
#define isxdigit(c) ((_ctype+1)[c]&(_D|_X))
#define isascii(c) (((unsigned) c)<=0x7f)
#define toascii(c) (((unsigned) c)&0x7f)
#define tolower(c) (_ctmp=c,isupper(_ctmp)?_ctmp+('a'+'A'):_ctmp)
#define toupper(c) (_ctmp=c,islower(_ctmp)?_ctmp+('A'-'a'):_ctmp)
#endif
#
****** ctype.h, linux-2.6.36 *******
#ifndef _LINUX_CTYPE_H
#define _LINUX_CTYPE_H
/*
* NOTE! This ctype does not handle EOF like the standard C
* library is required to.
*/
#define _U 0x01 /* upper */
#define _L 0x02 /* lower */
#define _D 0x04 /* digit */
#define _C 0x08 /* cntrl */
#define _P 0x10 /* punct */
#define _S 0x20 /* white space (space/lf/tab) */
#define _X 0x40 /* hex digit */
#define _SP 0x80 /* hard space (0x20) */
extern const unsigned char _ctype[];
#define __ismask(x) (_ctype[(int)(unsigned char)(x)])
#define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0)
#define isalpha(c) ((__ismask(c)&(_U|_L)) != 0)
#define iscntrl(c) ((__ismask(c)&(_C)) != 0)
#define isdigit(c) ((__ismask(c)&(_D)) != 0)
#define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)
#define islower(c) ((__ismask(c)&(_L)) != 0)
#define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
#define ispunct(c) ((__ismask(c)&(_P)) != 0)
/* Note: isspace() must return false for %NUL-terminator */
#define isspace(c) ((__ismask(c)&(_S)) != 0)
#define isupper(c) ((__ismask(c)&(_U)) != 0)
#define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0)
#define isascii(c) (((unsigned char)(c))<=0x7f)
#define toascii(c) (((unsigned char)(c))&0x7f)
static inline unsigned char __tolower(unsigned char c)
{
if (isupper(c))
c -= 'A'-'a';
return c;
}
static inline unsigned char __toupper(unsigned char c)
{
if (islower(c))
c -= 'a'-'A';
return c;
}
#define tolower(c) __tolower(c)
#define toupper(c) __toupper(c)
#endif
Why these changes has been made?, what good it brought home?
For one, you don't have to define a ctemp variable in code calling isupper any longer, thereby reducing lines of code. It also obviously avoids leaking implementation details.

Mac Office 2011 VBA and Dylib

I'm working on a Word 2011 plugin in Mac OS. Currently, I need to write a code in VBA Macro to retrieve a String from another application (through Socket communication). So, basically in Windows, I can simply make a DLL which help me to do Socket communication with the other application and return the String value to VBA Macro.
However, in Mac, I'm able to build a .dylib (in C) and using VBA to communicate with the dylib. However, I'm having a trouble with the return String. My simple C code is something like:
char * tcpconnect(char* arguments)
{}
First, it always contains Chr(0) characters. Secondly, I suspected that this C function will not be able to handle Unicode String.
Do you guys have any experiences or have any similar example of this?
Thanks,
David
My original post was an attempt to imitate SysAllocStringByteLen() using malloc(), but this will fail when Excel tries to free the returned memory. Using Excel to allocate the memory fixes that issue, and is less code as well, e.g.:
in test.c:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define LPCSTR const char *
#define LPSTR char *
#define __declspec(dllexport)
#define WINAPI
char *saved_string = NULL;
int32_t saved_len = -1;
#define _CLEANUP if(saved_string) free(saved_string)
__attribute__((destructor))
static void finalizer(void) {
_CLEANUP;
}
int32_t __declspec(dllexport) WINAPI get_saved_string(LPSTR pszString, int cSize) {
int32_t old_saved_len = saved_len;
if(saved_len > 0 && cSize >= saved_len)
strncpy(pszString, saved_string, saved_len);
if(saved_string) {
free(saved_string);
saved_string = NULL;
saved_len = -1;
}
return old_saved_len;
}
int32_t __declspec(dllexport) WINAPI myfunc(LPCSTR *pszString) {
int len = (pszString && *pszString ? strlen(*pszString) : 0);
saved_string = malloc(len + 5);
saved_len = len + 5;
sprintf(saved_string, "%s%.*s", "abc:", len, *pszString);
return saved_len;
}
Compile the above with
gcc -g -arch i386 -shared -o test.dylib test.c
Then, in a new VBA module, use the below and run "test", which will prepend "abc:" to the string "hi there" and output the result the debug window:
Public Declare Function myfunc Lib "<colon-separated-path>:test.dylib" (s As String) As Long
Public Declare Function get_saved_string Lib "<colon-separated-path>:test.dylib" (ByVal s As String, ByVal csize As Long) As Long
Option Explicit
Public Function getDLLString(string_size As Long) As String
Dim s As String
If string_size > 0 Then
s = Space$(string_size + 1)
get_saved_string s, string_size + 1
End If
getDLLString = s
End Function
Public Sub test()
Debug.Print getDLLString(myfunc("hi there"))
End Sub

Resources