Depressed "Serial communication"

Source: Internet
Author: User

/******************************************* program name:   1602 LCD Clock program writing time: October 4, 2015 hardware support: LCD1602 LCD screen   &NBSP;STC12C4052AD external 12MHZ crystal oscillator   Interface definition:        db0_db7 --> p1^0  --P1^7RS   = P3 ^ 2;RW   = P3 ^ 3; e    = p3 ^ 4;*******************************************/  #include  <STC12C2052AD.h>          //  contains header files  // typedef unsigned char uint8;  //  unsigned 8-bit integer variable  //#define &NBSP;LCD1602_DB0_DB7   P1   //  defining the LCM2402 data bus sbit lcd1602_rs   = p3 ^  2;   //  define LCM2402 's RS control line sbit lcd1602_rw   = p3 ^ 3 ;   //  defines the RW control line for LCM2402 sbit lcd1602_e    = p3 ^ 4;    // Defines the E control line of the LCM2402 sbit lcd1602_busy = p1 ^ 7;   //  Define LCM2402 lines (associated with LCD1602_DB0_DB7) unsigned char receive[32];unsigned char k; #define    CMD_clear   0x01 //  Clear Screen #define  cmd_back    0x02  // ddram back to 0 bits #define  cmd_dec1    0x04 //  ac (pointer) minus 1 after reading, write to left # define  cmd_add1    0x06 //  read-in AC (pointer) plus 1, write right #define  cmd_dis_ gb1 0x0f //  Open Display _ Open cursor _ Open cursor blinking #define  cmd_dis_gb2 0x0e //  on display _ Open cursor _ off cursor Blinking # define  cmd_dis_gb3 0x0c //  on show _ off cursor-off cursor blinking #define  cmd_off_dis 0x08  //  off Show _ off cursor-off cursor blinking #define  cmd_set82   0x38 // 8 bit bus _2 Line show # define   cmd_set81   0x30 // 8-bit bus _1 line display (top row) #define   CMD_set42    0x28 // 4 bit bus _2 line display #define&Nbsp; cmd_set41   0x20 // 4-bit bus _1 line display (top row) #define   lin_1        0x80 // 4-bit bus _1 line display (top row) #define   lin_2        0xc0 // 4 bit bus _1 line display (top row)  void DELAY_MS  (unsigned int a)  {unsigned int i;while  ( --a != 0 )    {for  (i=0;i <=600;i++);}}  void lcd1602_testbusy (void) {lcd1602_db0_db7 = 0xff;         LCD1602_RS = 0; lcd1602_rw = 1; Lcd1602_e = 1;delay_ms (2); while (Lcd1602_busy);          lcd1602_e = 0;                  delay_ms (2);}  void lcd1602_writecmd (Uint8 lcd1602_command)  { lcd1602_testbusy (); Lcd1602_db0_db7 = lcd1602_commanD lcd1602_rs = 0; lcd1602_rw = 0; Lcd1602_e = 1;delay_ms (2); Lcd1602_e = 0;delay_ms (2);}  void lcd1602_writedata (uint8 lcd1602_data) { lcd1602_testbusy (); lcd1602_db0_db7 = lcd1602_data; lcd1602_rs = 1; lcd1602_rw = 0; Lcd1602_e = 1;delay_ms (2); Lcd1602_e = 0;delay_ms (2);}   void print (UINT8&NBSP;A,UINT8&NBSP;*STR) {lcd1602_writecmd (a | 0x80); while (*str  !=  ' + ') {lcd1602_writedata (*str++);} *str = 0;}  void print2 (uint8 a,uint8 t) {lcd1602_writecmd (a | 0x80); Lcd1602_writedata (t);}  void lcd1602_init (void) {lcd1602_writecmd (cmd_set82);     //display mode setting: Displays 2 rows, each character is 5* 7 pixels lcd1602_writecmd (cmd_clear)     //display clear Lcd1602_writecmd (cmd_back);    The   //data pointer points to the 1th line 1th character position lcd1602_writecmd (CMD_ADD1);      //Displays the cursor movement settings: text does not move, Move the cursor right lcd1602_writecmd (Cmd_dis_GB3)   //display on and cursor settings: Display on, cursor on, flashing open}void init  (void) { //power-on initialization tmod = 0x11;          //  Timer/Counter 0, 1 working in mode 1   th0 = 0x3c;           //  preset 50ms Time Base signal    tl0 =  0xb0;   EA = 1;               //  Total Interruption    ET0 = 1;              //  Timer/Counter 0 allow interrupts    TR0 = 1;              //  Opening/Closing Timer/counter 0   }  Void receivem (void) {while (ri==1) {if (k==32) {k=0;} Receive[k]=sbuf; ri=0;k++;}} Void dis (void)  {unsigned char i;if (k>0 && k<16)  {LCD1602_ Writecmd (0x80); for (i=0;i<k;i++) {Lcd1602_writedata (recEive[i]);}} if (k>=16 && k<32) {lcd1602_writecmd (0xC0); for (i=16;i<k;i++) {Lcd1602_writedata ( Receive[i]);}}} Void uart_init (void) {ea=1; //Open total interrupt "timer, ADC, serial, compare, Count, external" interrupt type es=1; //allow the interrupt of the serial port tmod=0x20;   //  Timer 1&NBSP;T/C1 working mode, used to generate serial work frequency scon=0x50;  //  serial work mode 1th1=0xf3;   //   Timer initial value of high 8-bit settings, check the table frequency tl1=0xf3;    //  Timer Initial value of low 8-bit settings, check the table frequency pcon=0x80;  //   Baud rate multiplier 2400 is 4800 tr1=1;      //  timer start}  void uart_t   (Unsigned char uart_data) { sbuf = uart_data;                     while (TI ==  0);                       TI = 0;                               }  void UART_TC  (UNSIGNED&NBSP;CHAR&NBSP;*STR) {while (*str !=  ') {uart_t (*STR); *str++;} *str = 0;}  void uart_r (void)  interrupt 4 using 1{unsigned char UART_data; ri=0;                      uart_data=sbuf;           if ( UART_DATA==0X30)  {//        LED=~LED; uart_tc  ("Success! ");} Sbuf=uart_data; while (ti==0);   ti=0;            } void main  (void) {init ();//Initialize                              lcd1602_iNIT ();//lcm2402 initialization                             //uart_init (); while (1) { //dis (); Print (0x80, "http://990487026"),  print (0x40, ". blog.51cto.com/");  }} //void tiem0 (void)  interrupt 1{    ////  cou++;                       ////     if (cou > 1000)              //////        cou = 0;               ////    TH0 = 0x3c;                ////     TL0 = 0xb0; Receivem ();//}//display//http://990487026 //.blog.51cto.com/ 


This article comes from "Life is endless, tossing and turning." "blog, declined reprint!"

Depressed "Serial communication"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.