51单片机-PASCAL语言实例 13:非面向对象驱动LCD1602

实例12中,我用OOP编写了 LCD1602 驱动,测试时发现不能正确显示,研究很久也没有解决,另外发现OOP代码比非OOP代码长了400多字节,在单片机中有点多了,还是用回非OOP吧。电路图同上例,代码如下:

// TestLCD1602NotOOP
{
   
    // 51单片机 pascal 语言 示例
    // LCD1602 写字符
    // 使用 Turbo51 编译器
}

Program TestLCD1602NotOOP;

uses
    LCD1602NotOOP;
      
begin
    LCD1602_Init;
    LCD1602_Clear;
    LCD1602_Print1(2,'Hello First') ;
    LCD1602_Print2(3,'Good Two');
      
end.
// LCD1602PortDef.inc
 var       
    LCD1602_RS: boolean absolute P0.4 ;
    LCD1602_RW: boolean absolute P0.3  ;
    LCD1602_EN: boolean absolute p0.2  ;
    LCD1602_Data:Byte  absolute P2 ;
// LCD1602NotOOP.PAS
{
   
    // 51单片机 pascal 语言 示例
    // LCD1602 写字符
    // 使用 Turbo51 编译器
}
    Unit LCD1602NotOOP;

    interface
    type
        STR16=String[16]; 
        LCD1602_X=0..15 ; 
        
    procedure LCD1602_Init;
    procedure LCD1602_Clear;
    // 在第1行输出
    procedure LCD1602_Print1(X:LCD1602_X;AStr:STR16 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是 Pascal 程序设计语言的文法实例: ``` <program> ::= program <identifier> ; <block> . <block> ::= <declaration-part> <statement-part> <declaration-part> ::= <label-declaration-part> <constant-definition-part> <type-definition-part> <variable-declaration-part> <procedure-and-function-declaration-part> <label-declaration-part> ::= label <label> { , <label> } ; <label> ::= <unsigned-integer> <constant-definition-part> ::= const <constant-definition> { ; <constant-definition> } ; <constant-definition> ::= <identifier> = <constant> <constant> ::= <unsigned-number> | <sign> <unsigned-number> | <string> | <identifier> <type-definition-part> ::= type <type-definition> { ; <type-definition> } ; <type-definition> ::= <identifier> = <type> <type> ::= <simple-type> | <structured-type> | <pointer-type> <simple-type> ::= <scalar-type> | <subrange-type> | <enumerated-type> | <set-type> <scalar-type> ::= <identifier> <subrange-type> ::= <constant> .. <constant> <enumerated-type> ::= ( <identifier> { , <identifier> } ) <set-type> ::= set of <base-type> <base-type> ::= <scalar-type> <structured-type> ::= <array-type> | <record-type> <array-type> ::= array [ <index-range> { , <index-range> } ] of <component-type> <index-range> ::= <simple-type> <component-type> ::= <type> <record-type> ::= record <field-list> end <field-list> ::= <fixed-part> | <fixed-part> ; <variant-part> | <variant-part> <fixed-part> ::= <record-section> { ; <record-section> } ; <variant-part> ::= case <tag-field> of <variant> { ; <variant> } ; [ else <field-list> ] end ; <tag-field> ::= <identifier> : <type> <variant> ::= <variant-selector> : ( <field-list> ) <variant-selector> ::= <constant> .. <constant> | <identifier> <variable-declaration-part> ::= var <variable-declaration> { ; <variable-declaration> } ; <variable-declaration> ::= <identifier> { , <identifier> } : <type> <procedure-and-function-declaration-part> ::= <procedure-declaration> | <function-declaration> | <procedure-declaration> ; <function-declaration> <procedure-declaration> ::= procedure <identifier> ; [ <formal-parameter-list> ] ; <block> ; <function-declaration> ::= function <identifier> ; [ <formal-parameter-list> ] : <type> ; <block> ; <formal-parameter-list> ::= ( [ <parameter-group> { ; <parameter-group> } ] ) <parameter-group> ::= <identifier-list> : <parameter-type> <identifier-list> ::= <identifier> { , <identifier> } <parameter-type> ::= <simple-type> | <structured-type> | <identifier> <statement-part> ::= <compound-statement> <compound-statement> ::= begin <statement> { ; <statement> } end <statement> ::= <simple-statement> | <structured-statement> <simple-statement> ::= <assignment-statement> | <procedure-call-statement> | <goto-statement> | <empty-statement> <assignment-statement> ::= <variable-access> := <expression> <procedure-call-statement> ::= <identifier> [ <actual-parameter-list> ] <actual-parameter-list> ::= <expression> { , <expression> } <goto-statement> ::= goto <label> <empty-statement> ::= <structured-statement> ::= <compound-statement> | <conditional-statement> | <repetitive-statement> | <with-statement> <conditional-statement> ::= if <expression> then <statement> [ else <statement> ] <repetitive-statement> ::= <while-statement> | <repeat-statement> | <for-statement> <while-statement> ::= while <expression> do <statement> <repeat-statement> ::= repeat <statement> { ; <statement> } until <expression> <for-statement> ::= for <control-variable> := <for-list> do <statement> <control-variable> ::= <identifier> <for-list> ::= <initial-value> [ to | downto ] <final-value> <initial-value> ::= <expression> <final-value> ::= <expression> <with-statement> ::= with <record-variable-list> do <statement> <record-variable-list> ::= <variable-access> { , <variable-access> } <expression> ::= <simple-expression> | <simple-expression> <relational-operator> <simple-expression> <relational-operator> ::= = | <> | < | <= | >= | > <simple-expression> ::= <term> | <sign> <term> | <simple-expression> <adding-operator> <term> <sign> ::= + | - <adding-operator> ::= + | - | or <term> ::= <factor> | <term> <multiplying-operator> <factor> <multiplying-operator> ::= * | / | div | mod | and <factor> ::= <variable-access> | <unsigned-constant> | ( <expression> ) | <function-designator> <variable-access> ::= <variable> { <indexed-selector> | <field-selector> } <variable> ::= <identifier> <indexed-selector> ::= [ <expression> { , <expression> } ] <field-selector> ::= . <identifier> <unsigned-constant> ::= <unsigned-number> | <string> | <constant-identifier> <function-designator> ::= <identifier> [ <actual-parameter-list> ] <string> ::= '<character> { <character> }' <constant-identifier> ::= <identifier> ``` 注意:这只是 Pascal 的一个简单实现,实际上 Pascal 的语法常复杂,因此这里只提供了一部分重要的规则。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值