Tomas_Yung 发表于 2011-1-2 18:34:18

电脑串口驱动1602液晶

http://cache.amobbs.com/bbs_upload782111/files_35/ourdev_608667P5071O.jpg
(原文件名: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);      /* 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);
}

maxims 发表于 2012-9-5 22:55:05

好主意。。。。
页: [1]
查看完整版本: 电脑串口驱动1602液晶