Пример #1
0
//屏幕秒闪烁一次
void LCD1602::flicker_screen(void)
{
	wcmd(0x08);//关显示
	lcd_delay(0x3fffff);
	wcmd(0x0C);//开显示
	lcd_delay(0x3fffff);
}
Пример #2
0
/*********************************************************************
*名    称:Init()
*功    能:初始化LCD1602
*入口参数:无
*出口参数:无
*常用命令:0x38:16*2显示,5*&点阵显示字符,8位数据;指令执行时间40us
 *         0x0C:开显示,关光标	  40us
 *         0x08:关显示,关光标	  40us
 *         0x0D:字符闪烁,关光标,接着设定位置,闪烁周期0.4ms左右
 *         0x0F:字符闪烁,开光标
 *         0x06:写完数据自动右移光标,普通情形,从左向右显示  40us
 *         0x04:写完数据自动左移光标,可以从右向左显示	 40us
 *         0x01:清除显示内容,即清屏  1.64ms
 *         0x02:使光标还回起始位置	  1.64ms
 *         0x18:屏幕上所有字符同时左移一格,适合滚动显示 40us
 *         0x1C:屏幕上所有字符同时右移一格,适合滚动显示 40us
*********************************************************************/
void LCD1602::begin(void)
{   
	led->mode(OUTPUT_PP);
	en->mode(OUTPUT_PP);
	rw->mode(OUTPUT_PP);
	rs->mode(OUTPUT_PP);
	d0->mode(OUTPUT_PP);
	d1->mode(OUTPUT_PP);
	d2->mode(OUTPUT_PP);
	d3->mode(OUTPUT_PP);
	d4->mode(OUTPUT_PP);
	d5->mode(OUTPUT_PP);
	d6->mode(OUTPUT_PP);
	d7->mode(OUTPUT_PP);

	wcmd(0x38);  //16*2显示,5*7点阵,8位数据
	lcd_delay(100);
	wcmd(0x38);  //16*2显示,5*7点阵,8位数据
	lcd_delay(100);
	wcmd(0x38);  //16*2显示,5*7点阵,8位数据
	lcd_delay(100);
	wcmd(0x08);  //先关显示,后开显示
	lcd_delay(100);
	wcmd(0x01);  //清除LCD的显示内容
	lcd_delay(100);
	wcmd(0x06);  //自动右移光标,0x04为左移光标
	lcd_delay(100);
	wcmd(0x0c);  //显示开,关光标;0x08为关显示
	lcd_delay(100);
	back_light(1);
}
Пример #3
0
/********************************************************************
* 名称 : L1602_char(uchar hang,uchar lie,char sign)
* 功能 : 改变液晶中某位的值,如果要让第一行,第五个字符显示"b" ,调用该函数如下
		 L1602_char(1,5,'b')
* 输入 : 行,列,需要输入1602的数据
* 输出 : 无
***********************************************************************/
void L1602_char(uchar hang,uchar lie,char sign)
{
	uchar a;
	if(hang == 1) a = 0x80;
	if(hang == 2) a = 0xc0;
	a = a + lie - 1;
	wcmd(a);
	wdata(sign);
}
Пример #4
0
/********************************************************************
* 名称 : L1602_init()
* 功能 : 1602初始化,请参考1602的资料
* 输入 : 无
* 输出 : 无
***********************************************************************/
void L1602_init(void)
{
	wcmd(0x38);
	Delay_1ms(5);
	wcmd(0x38);
	Delay_1ms(5);
	wcmd(0x38);
	Delay_1ms(5);
	wcmd(0x38);
	wcmd(0x08);	
	wcmd(0x0c);
	wcmd(0x04);
	wcmd(0x01);
}
Пример #5
0
/********************************************************************
* 名称 : L1602_string(uchar hang,uchar lie,uchar *p)
* 功能 : 改变液晶中某位的值,如果要让第一行,第五个字符开始显示"ab cd ef" ,调用该函数如下
	 	 L1602_string(1,5,"ab cd ef;")
* 输入 : 行,列,需要输入1602的数据
* 输出 : 无
***********************************************************************/
void L1602_string(uchar hang,uchar lie,uchar *p)
{
	uchar a,b=0;
	if(hang == 1) a = 0x80;
	if(hang == 2) a = 0xc0;
	a = a + lie - 1;
	while(1)
	{
		wcmd(a++);		
		if((*p == '\0')||(b==16)) break;
		b++;
		wdata(*p);
		p++;
	}
}
Пример #6
0
//清屏,清除显示
void LCD1602::clear(void)
{
	wcmd(0x01);
}
Пример #7
0
void LCD1602::flicker_char(uint8_t row,uint8_t col)
{
	wcmd(0x0D);
	set_pos(row,col);
}
Пример #8
0
//关闭字符闪烁
void LCD1602::close_flicker(void)
{
	wcmd(0x0C);
}
Пример #9
0
//开显示
void LCD1602::open(void)
{
	wcmd(0x0C);
}
Пример #10
0
/*********************************************************************
*名    称:FlickerChar()
*功    能:使指定位置字符闪烁,不显示光标
*入口参数:row:行 1,2  
 *         col:列 0~15
*出口参数:无
*说    明:写命令0x0D不显示光标的闪烁,写命令0x0F是显示光标的闪烁
 *         一旦设定闪烁后,会根据位置变化闪烁,关闪烁写命令0x0C
*********************************************************************/
void LCD1602::flicker(void)
{
	wcmd(0x0D);
}
Пример #11
0
int
main(int argc, char **argv)
{
  /* network */
  int		       err, listenfd, telnetfd, connfd, maxfdp1, nready;
  struct sockaddr_in   servaddr, tnservaddr;
  char		       readline[MAXLINE];

  /* data */
  struct cmd           cmd;
  struct wthio         wio;
  int                  ndata = 0;
  int                  nobg = 0;
  int                  is_command = 0;
  int                  o;
  unsigned char        data[MAXBUFF];
  char                 *nakfram = "\x02\x01\x15\xe8\x03";
  char                 *rbuf;
  fd_set               rset;
	
  werrno = 0;

  initdata(&wio);
  initcmd(&cmd);
  readconfig(&cmd);
	
  /* parse commandline */
  while ((o = getopt(argc, argv, "dp:")) != -1) {
    switch(o) {
    case 'd':
      nobg = 1;
      break;
    case 'p':
      cmd.port = strdup(optarg);
      break;
    case '?':
      usaged(1,"command line error","");
      break;
    default:
      usaged(0, "", "");
    }
  }

  if ( nobg == 0 ) 
    daemon_init("wthd", LOGFACILITY);
  else if ( nobg == 1) {
    openlog("wthd", LOG_PID, LOGFACILITY);
    printf("wthd: ready\n");
  }
	
  /* create 1st TCP socket */
  listenfd = Socket(AF_INET, SOCK_STREAM, 0); 
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family      = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port        = htons(atoi(cmd.port));
  Bind(listenfd, (SA *) &servaddr, sizeof(servaddr));
  Listen(listenfd, LISTENQ);


  /* create 2nd TCP socket */
  telnetfd = Socket(AF_INET, SOCK_STREAM, 0);
  bzero(&tnservaddr, sizeof(tnservaddr));
  tnservaddr.sin_family      = AF_INET;
  tnservaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  tnservaddr.sin_port        = htons(atoi(cmd.tnport));
	
  Bind(telnetfd, (SA *) &tnservaddr, sizeof(tnservaddr));
  Listen(telnetfd, LISTENQ);

  FD_ZERO(&rset);
  maxfdp1 = max(listenfd, telnetfd) + 1;

  for ( ; ; ) {
    FD_SET(listenfd, &rset);
    FD_SET(telnetfd, &rset);

    if ( ( nready = select(maxfdp1, &rset, NULL, NULL, NULL)) < 0 ) {
      if ( errno == EINTR )
	continue;
      else
	syslog(LOG_INFO, "select error");
    }

    if ( FD_ISSET(listenfd, &rset)) {
      connfd = accept(listenfd, (SA *) NULL, NULL); 
      Read(connfd, readline, MAXLINE);
      cmd.command = o = atoi(readline);
      cmd.argcmd  = 0;
      cmd.netflg  = 0;
         
      if ( getsrd( data, &ndata, &cmd) == -1 ) {
	syslog(LOG_INFO,"error reading serial data");
	strncpy(data, nakfram, strlen(nakfram));
	ndata = strlen(nakfram);
      }
		 
      Write(connfd, data, ndata);
      /* syslog(LOG_INFO,"command request: %s\n", c(o)->descr); */
      Close(connfd);
    }
		
    if ( FD_ISSET(telnetfd, &rset)) {
      connfd = Accept(telnetfd, (SA *) NULL, NULL);
      snprintf(readline, sizeof(readline), "\n\n%s\n\t%s\n>",
	       "Welcome to wth service","Type h for help");
      Write(connfd, readline, strlen(readline));
      cmd.argcmd = 0;
      cmd.netflg = 0;
      for ( ; ; ) {
	Read(connfd, readline, MAXLINE);

	if ( ( err = strncmp(readline, "h", 1)) == 0 ) {
	  snprintf(readline, sizeof(readline), tnusage(0,"",""));
	  Write(connfd, readline, strlen(readline));
	}
	else if ( ( err = strncmp(readline, "0", 1)) == 0) {
	  cmd.command = o = atoi(readline);
	  is_command = 1;
	}
	else if ( ( err = strncmp(readline, "1", 1)) == 0) {
	  cmd.command = o = atoi(readline);
	  is_command = 1;
	}
	else if ( ( err = strncmp(readline, "2", 1)) == 0) {
	  cmd.command = o = atoi(readline);
	  is_command = 1;
	}
	else if ( ( err = strncmp(readline, "3", 1)) == 0) {
	  cmd.command = o = atoi(readline);
	  is_command = 1;
	}
	else if ( ( err = strncmp(readline, "4", 1)) == 0) {
	  cmd.command = o = atoi(readline);
	  is_command = 1;
	}
	else if ( ( err = strncmp(readline, "5", 1)) == 0) {
	  cmd.command = o = atoi(readline);
	  is_command = 1;
	}
	else if ( ( err = strncmp(readline, "q", 1)) == 0)
	  break;
	else if ( ( err = strncmp(readline, "quit", 4)) == 0)
	  break;
	else {
	  snprintf(readline, sizeof(readline), tnusage(0,"",""));
	  Write(connfd, readline, strlen(readline));
	}
			
	if ( is_command == 1 ) {
	  rbuf = wcmd(&cmd, &wio);
	  printf("rbuf: %s\n", rbuf);
	  snprintf(readline, sizeof(readline), rbuf);
	  Write(connfd, readline, strlen(readline));
	  cmd.argcmd  = 0;
	  cmd.netflg  = 0;
	  is_command = 0;
	}
			
	snprintf(readline, sizeof(readline), ">");
	Write(connfd, readline, strlen(readline));
      }
      Close(connfd);
    }
		
  }
  return(0);
}
Пример #12
0
//关显示
void LCD1602::close(void)
{
	wcmd(0x08);
}
Пример #13
0
int main (int argc, char **argv) {
  int o;
  char *rbuf;
  extern int optind;              
  extern char *optarg;
  struct cmd cmd;                 /* command structure */
  struct wthio wio;               /* result */


  initdata(&wio);
  initcmd(&cmd);
  if ( ( rbuf = readconfig(&cmd)) == NULL ) {
	perror("Error reading configuration: exit!");
	exit(-1);
  }
  
  openlog("wthc", LOG_PID , cmd.logfacility);
  syslog(LOG_INFO, "%s\n", wth_version);
                                                                    
  /* parsing command line arguments */
  while (( o = getopt(argc, argv, "c:h:i:p:sv")) != -1 ) {
      switch (o) {
	  case 'c':
          cmd.command = atoi(optarg);
	      break;
	  case 'h':
	      cmd.hostname = optarg;
          cmd.netflg = 1;
	      break;
	  case 'i':
          cmd.argcmd = atoi(optarg);
	      break;
	  case 'p':
          cmd.port = optarg;
	      break;
      case 's':
	      if ( cmd.netflg != -1 )
		    usage(1,"specify serial OR internet connection","");
	      cmd.netflg = 0;
	      break;
      case 'v':
		  cmd.verbose = 1;
		  printf("wthc: %s\n", wth_version);
		  printf("%s", rbuf);
		  break;
      case '?':
	      usage(1, "Commandline error", "");
	      break;
      default:
	      usage(0,"", "");
       }
   }

  /* save command for later use */
  o = cmd.command;

  /* check if intervall time has been set 
     in case cmd.command is request to set intervall time */
  if ( cmd.command == 6 ) {
      if ((cmd.argcmd < 1) || (cmd.argcmd >60))
	  usage(1,"interval time not been specified or out of range", "");
  }

  /* check on serial/internet connection is been chosen correctly */
  if ( cmd.netflg == -1 )
      usage(1, "specify serial OR internet connection","");

  if (cmd.verbose == 1 ) {
	if ( ( rbuf = echoconfig(&cmd)) == NULL) {
	  perror("Error echo config parameters: exit!");
	  exit(-1);
	}
	printf("%s\n", rbuf);
  }
  
  /* sending command to weather station */  
  rbuf =  wcmd(&cmd, &wio); 
  printf("%s", rbuf);
  syslog(LOG_INFO, "wthc : wcmd : %s\n", c(o)->descr);
  
  switch (werrno) {
  case -2:
	printf("serial line error\n");
	break;
  case -3:
    printf("chksum error\n");
	break;
  case 0:
	break;
  }
  closelog();
  
  return(0);  
} 
Пример #14
0
//屏幕整体右移一格,用于滚动显示
void LCD1602::shift_right(void)
{
	wcmd(0x1C);
}
Пример #15
0
//屏幕整体左移一格,用于滚动显示
void LCD1602::shift_left()
{
	wcmd(0x18);
}
Пример #16
0
/*********************************************************************
*名    称:setPos()
*功    能:根据习惯设定显示位置
*入口参数:row:行,row=1表示第一行,row=2表示第二行
 *         col:列,0~15,用于指定显示的列,范围可以是0~40
*出口参数:无
*********************************************************************/
void LCD1602::set_pos(uint8_t row,uint8_t col)
{
	if(row==1) wcmd(col | 0x80);
	else wcmd(col | 0xC0);
}
Пример #17
0
/*********************************************************************
*名    称:pos()
*功    能:设定显示位置
*入口参数:pos:显示位置,值的范围如下:
 *   0x00----------------0x0f 0x10-------0x27 第一行(一次显示16个字符)
 *   0x40----------------0x4f 0x50-------0x67 第二行
*出口参数:无
*********************************************************************/
void LCD1602::pos(uint8_t pos)
{                         
	wcmd(pos | 0x80);
}
Пример #18
0
int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nFunsterStil)
{
	MSG messages;
	globallog = new char[1];globallog[0]=32;
	globallogsize=1;
	backbar=0;
//	globallog = (char*)Mrealloc(2);
	
	wincl.hInstance = hThisInstance;
	wincl.lpszClassName = szClassName;
	wincl.lpfnWndProc = WindowProcedure;
	wincl.style = CS_DBLCLKS;
	wincl.cbSize = sizeof (WNDCLASSEX);
	
	wincl.hIcon = LoadIcon( hThisInstance, "A" );
	wincl.hIconSm = wincl.hIcon;
	wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
	wincl.lpszMenuName = NULL;
	wincl.cbClsExtra = 0;
	wincl.cbWndExtra = 0;
	wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	
			memset(&note,0,sizeof(note));
			note.cbSize=sizeof(NOTIFYICONDATA);
			note.hWnd=hwnd;
			note.uID=0;
			note.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP;
			note.hIcon=wincl.hIcon;
			note.uCallbackMessage=WM_USER+5;
			lstrcpy(note.szTip,szClassName);

	if (!RegisterClassEx (&wincl)) return 0;
	RECT lp;
	GetWindowRect(GetDesktopWindow(),&lp);
	int w=GetSystemMetrics(SM_CXSCREEN);
	int h=GetSystemMetrics(SM_CYSCREEN);
	hwnd =CreateWindowEx (0,szClassName,"patterns",WS_CAPTION|WS_MINIMIZEBOX|WS_VISIBLE|WS_SYSMENU,lp.right-414,0,414,670,HWND_DESKTOP,NULL,hThisInstance,NULL);//CW_USEDEFAULT
	hlog =CreateWindowEx (0,"Edit","",WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOVSCROLL|ES_NOHIDESEL|WS_VSCROLL,0,0,438,630,hwnd,NULL,hThisInstance,NULL);
//	hcmd =CreateWindowEx (0,"Edit","",WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOVSCROLL|ES_NOHIDESEL|WS_VSCROLL,0,310,538,20,hwnd,NULL,hThisInstance,NULL);
//	hcmd =CreateWindowEx (WS_EX_CLIENTEDGE,"ListBox","",WS_CHILD|WS_VISIBLE|WS_VSCROLL|LVS_REPORT | LVS_SHAREIMAGELISTS,0,260,538,70,hwnd,NULL,hThisInstance,NULL);
	hpro =CreateWindowEx (0,"Static"," ",WS_CHILD | WS_VISIBLE,0,630,380,20,hwnd,NULL,hThisInstance,NULL);
	
/*    SendMessage( hcmd, LVM_FIRST+54, 0, 32 | 16 | 2 | 1);

	ListView_SetTextColor(hcmd,0x00000000);
	SendMessage( hcmd, LVM_SETTEXTBKCOLOR, 0, 0x00ffffef);
	ListView_SetBkColor(hcmd,0xffffef);
	ListBox_InsertString(hcmd,0,"MMCIS-Real");
    ListBox_InsertString(hcmd,0,"MMCIS-Demo");
	LV_ITEM lvi;//memset(&lvi,0,sizeof(LV_ITEM));
LV_COLUMN lvc;
lvc.pszText="dfg";
lvc.cx=44;
lvc.iSubItem=0;
ListView_InsertColumn(hcmd,1,&lvc);
	ListBox_SetColumnWidth(hcmd,41);
	lvi.cchTextMax=22;
	lvi.iItem=0;
	lvi.lParam=0;
	lvi.iSubItem=1;
	lvi.mask=LVIF_PARAM;
	lstrcat(lvi.pszText," subitem ");
	//ListBox_InsertItemData(hcmd,0,&lvi);
	SendMessage(hcmd, LVM_SETITEM, 0, (LPARAM)&lvi);
//	lvi.mask=LVIF_TEXT;
	lvi.cchTextMax=12;
	lvi.iItem=0;
	lvi.lParam=1;
	lvi.iSubItem=1;
//	lstrcat(lvi.pszText," subitem ");
	ListBox_InsertItemData(hcmd,0,&lvi);
	SendMessage(hcmd, LVM_SETTEXTCOLOR, 0, (LPARAM)(COLORREF)0xff0f00ff);
	ListView_Update(hcmd,0);
	ListView_RedrawItems(hcmd,0,3);
*/
//mysqltest();
    if(find(lpszArgument,"/quit"))ShowWindow (hwnd, SW_HIDE); else
	ShowWindow (hwnd, nFunsterStil);
	UpdateWindow(hwnd);
	srand(time(0));
    if(find(lpszArgument,"/opt"))action=optimizing;else
    if(find(lpszArgument,"/test")){
		action=testing;
		hbup =CreateWindowEx (0,"Button"," ",WS_CHILD | WS_VISIBLE,40,630,10,10,hwnd,NULL,hThisInstance,NULL);
		hbdn =CreateWindowEx (0,"Button"," ",WS_CHILD | WS_VISIBLE,40,640,10,10,hwnd,NULL,hThisInstance,NULL);
		hbackbar =CreateWindowEx (0,"Static"," ",WS_CHILD | WS_VISIBLE,20,630,20,20,hwnd,NULL,hThisInstance,NULL);title(whbackbar,intToStr(backbar));
	}else
    if(find(lpszArgument,"/debug"))action=debuging;

    if(find(lpszArgument,"/1t"))period=1;else
    if(find(lpszArgument,"/5t"))period=5;else
    if(find(lpszArgument,"/15t"))period=15;else
    if(find(lpszArgument,"/60t"))period=60;else
    if(find(lpszArgument,"/240t"))period=240;else
    if(find(lpszArgument,"/1440t"))period=1440;else
    if(find(lpszArgument,"/10080t"))period=10080;else
    if(find(lpszArgument,"/43200t"))period=43200;

	mode=999;

	if(find2(lpszArgument,"/MMCIS-Demo"))mode=light;else
    if(find2(lpszArgument,"/MMCIS-Real"))mode=medium;else
    if(find2(lpszArgument,"/InstaForex-Demo.com"))mode=hard;
    
    if(find(lpszArgument,"/quit")){PostMessageA(hwnd,WM_SIZE,SIZE_MINIMIZED,0);GetMessage (&messages, NULL, 0, 0);TranslateMessage(&messages);DispatchMessage(&messages);}

//	server = new Server;
//    if(action==optimizing)server->on(false);else server->on();

    if(mode==999)wlog("Optimization: patterns.exe /MMCIS-Demo /opt /1440t\r\nTesting: patterns.exe /MMCIS-Demo /test /1440t\r\nDebuging: patterns.exe /MMCIS-Demo /debug /1440t\r\n\r\naction: /opt,/test,/debug\r\nperiod: /1t,/5t,/15t,/60t,/240t,/1440t,/10080t,/43200t\r\nmode: /MMCIS-Demo,/MMCIS-Real,/InstaForex-Demo.com\r\n\r\nExample: mt5\\bases\\MetaQuotes-Demo\\history\\patterns.exe /MMCIS-Demo /opt /1440t\r\n");
	else 
	if(action!=optimizing)decode(action,period,mode,donottradecurrentbar,backbar);
	else decode(action,period,mode,tradecurrentbar,backbar);
    InvalidateRect(hwnd,0,true);
    if(!find(lpszArgument,"/quit"))
	while (GetMessage (&messages, NULL, 0, 0))
	{if((messages.hwnd==hcmd)&&(messages.message==WM_KEYUP)&&messages.wParam==VK_RETURN)wcmd(cmdmain);
	if((messages.hwnd==hcmd)&&(messages.message==WM_LBUTTONDBLCLK))wlog(intToStr(ListBox_GetCurSel(hcmd) ));
	if((messages.hwnd==hbup)&&(messages.message==WM_LBUTTONUP)){backbar++;if(backbar>21)backbar=21;else title(whbackbar,intToStr(backbar));decode(action,period,mode,donottradecurrentbar,backbar);InvalidateRect(hwnd,0,true);}
	if((messages.hwnd==hbdn)&&(messages.message==WM_LBUTTONUP)){backbar--;if(backbar<-1)backbar=-1;else title(whbackbar,intToStr(backbar));decode(action,period,mode,donottradecurrentbar,backbar);InvalidateRect(hwnd,0,true);}
		TranslateMessage(&messages);
		DispatchMessage(&messages);
	}

	wlogsave();
	if(find(lpszArgument,"/quit")){Shell_NotifyIcon(NIM_DELETE,&note);GetMessage (&messages, NULL, 0, 0);TranslateMessage(&messages);DispatchMessage(&messages);}

	delete[] globallog;
	return messages.wParam;
}
Пример #19
0
//使光标还回原点位置
void LCD1602::Return(void)
{
	wcmd(0x02);
}