搜索
bottom↓
回复: 1

电脑串口驱动1602液晶

[复制链接]

出0入0汤圆

发表于 2011-1-2 18:34:18 | 显示全部楼层 |阅读模式

(原文件名:11.jpg)

基于C语言编写的源代码与上面的电路。该方案只发送通过RS-232端口(输出)数据,并没有收到任何数据。正在使用的通信格式8,1,9600
/* Name       : Sample LCD Program for Serial/RS-232 Port  */
/* Written By : Craig Peacock <cpeacock@senet.com.au> 1997 */

#include <dos.h>
#include <stdio.h>
#include <conio.h>

#define PORT1 0x3E8  /* Port Address Goes Here */

  /* Defines Serial Ports Base Address */
  /* COM1 0x3F8                        */
  /* COM2 0x2F8                               */
  /* COM3 0x3E8                               */
  /* COM4 0x2E8                               */

void main(void)
{
int c;
int count;
char init[] = { 0x0F, 0x01, 0x38 };
                 /* 0x0F - Init Display */
                 /* 0x01 - Clear Display */
                 /* 0x38 - Dual Line / 8 Bits */

outportb(PORT1 + 1 , 0x0);   /* Turn off interrupts - Port1 */
outportb(PORT1 + 3 , 0x80);  /* SET DLAB ON */
outportb(PORT1 + 0 , 0x0C);  /* Set Baud rate - Divisor Latch Low Byte */
                              /*         0x06 =  19,200 BPS */
                              /*         0x0C =   9,600 BPS */
                              /*         0x18 =   4,800 BPS */
                              /*         0x30 =   2,400 BPS */
outportb(PORT1 + 1 , 0x00);  /* Set Baud rate - Divisor Latch High Byte */
outportb(PORT1 + 3 , 0x03);  /* 8 Bits, No Parity, 1 Stop Bit */
outportb(PORT1 + 2 , 0xC7);  /* FIFO Control Register */
outportb(PORT1 + 4 , 0x0B);  /* Turn on DTR, RTS, and OUT2 */

outportb(PORT1 + 4 , (inportb(PORT1 + 4) | 0x01)); /* Register Select (DTR) */
                                                    /* 0 = Instruction Register */

for (count = 0; count < 3; count++)
  {
   outportb(PORT1, init[count]);      /* Send Init Data Bytes */
   delay(20);                         /* Larger Delay for INIT */
  }

outportb(PORT1 + 4 , (inportb(PORT1 + 4) & 0xFE)); /* Register Select (DTR) */
                                                    /* 1 = Data Register */

printf("\nSample Serial LCD Program. Press ESC to quit \n");

do {
     if (kbhit()){
                  c = getch();
                  outportb(PORT1, c);
                  printf("%c",c);
                 }

    } while (c !=27);
}

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 2012-9-5 22:55:05 | 显示全部楼层
好主意。。。。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-16 08:20

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表