Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<msp430x14x.h>
- ///DEFINICJE---------------------------------------------------------------------------------------
- #define bitset(var, bitno) ((var) |= 1 << (bitno)) //toggle E for LCD
- #define bitclr(var, bitno) ((var) &= ~(1 << (bitno)))
- #define LCD_Data P2OUT
- #define _100us 100 //
- #define _10us 10 //
- #define E 3 //P2.3
- #define RS 2 //P2.2
- #define CLR_DISP 0x01 // clear display
- #define CUR_HOME 0x02 // return home
- #define ENTRY_INC 0x06 // entry mode increment
- #define ENTRY_INC_ROL 0x07 // entry mode increment with rol data
- #define ENTRY_DEC 0x04 // entry mode decrement
- #define ENTRY_DEC_ROL 0x05 // entry mode decrement witch rol dat
- #define DISP_OFF 0x08 // all display offconst char font0[8] = {0x10, 0x10, 0x10, 0x14, 0x18, 0x10, 0x1E, 0x00};
- #define DISP_ON 0x0c // all display on
- #define DATA_ROL_LEFT 0x18 // rol data left
- #define DATA_ROL_RIGHT 0x1c // rol data right
- #define CUR_SHIFT_LEFT 0x10 // shift coursor left
- #define CUR_SHIFT_RIGHT 0x14 // shift coursor right
- #define DD_RAM_ADDR 0x80 // set DD_RAM
- #define DD_RAM_ADDR2 0xc0 // set CG_RAM
- #define DD_RAM_ADDR3 0x28 //
- #define CG_RAM_ADDR 0x40 //
- ///KONIEC DEFINICJI-----------------------------------------------------------------------------------
- /*unsigned char i;
- unsigned char znak;
- */
- ///deklaracje
- void InitPortsLcd(void); //inicjalizacja portów
- void InitLCD(void);
- void clearDisplay();
- void gotoSecondLine();
- void Delay(unsigned int a);
- void Delayx100us(unsigned char b);
- void _E(void);
- void SEND_CHAR(unsigned char d);
- void SEND_CMD(unsigned char e);
- void printFloat(float number);
- ///FUNKCJE-------------------------------------------------------------
- void InitPortsLcd(void) //inicjalizacja portów
- {
- P2SEL = 0;
- P2OUT = 0;
- P2DIR = ~BIT0; //only P2.0 is input
- }
- void InitLCD(void) {
- bitclr(P2OUT, RS);
- Delayx100us(250); //Delay 100ms
- Delayx100us(250);
- Delayx100us(250);
- Delayx100us(250);
- LCD_Data |= BIT4 | BIT5; //D7-D4 = 0011
- LCD_Data &= ~BIT6 & ~BIT7;
- _E(); //toggle E for LCD
- Delayx100us(100); //10ms
- _E(); //toggle E for LCD
- Delayx100us(100); //10ms
- _E(); //toggle E for LCD
- Delayx100us(100); //10ms
- LCD_Data &= ~BIT4;
- _E(); //toggle E for LCD
- SEND_CMD(DISP_ON);
- SEND_CMD(CLR_DISP);
- Delayx100us(250);
- Delayx100us(250);
- Delayx100us(250);
- Delayx100us(250);
- }
- void clearDisplay() {
- SEND_CMD(CLR_DISP);
- Delayx100us(10);
- }
- void gotoSecondLine() {
- SEND_CMD(DD_RAM_ADDR2);
- }
- void Delay(unsigned int a) {
- int k;
- for (k = 0; k != a; ++k) {
- _NOP();
- _NOP();
- _NOP();
- _NOP();
- }
- }
- void Delayx100us(unsigned char b) {
- int j;
- for (j = 0; j != b; ++j) Delay(_100us);
- }
- void _E(void) {
- bitset(P2OUT, E); //toggle E for LCD
- Delay(_10us);
- bitclr(P2OUT, E);
- }
- void SEND_CHAR(unsigned char d) {
- int temp;
- Delayx100us(5); //.5ms
- temp = d & 0xf0; //get upper nibble
- LCD_Data &= 0x0f;
- LCD_Data |= temp;
- bitset(P2OUT, RS); //set LCD to data mode
- _E(); //toggle E for LCD
- temp = d & 0x0f;
- temp = temp << 4; //get down nibble
- LCD_Data &= 0x0f;
- LCD_Data |= temp;
- bitset(P2OUT, RS); //set LCD to data mode
- _E(); //toggle E for LCD
- }
- void SEND_CMD(unsigned char e) {
- int temp;
- Delayx100us(10); //10ms
- temp = e & 0xf0; //get upper nibble
- LCD_Data &= 0x0f;
- LCD_Data |= temp; //send CMD to LCD
- bitclr(P2OUT, RS); //set LCD to CMD mode
- _E(); //toggle E for LCD
- temp = e & 0x0f;
- temp = temp << 4; //get down nibble
- LCD_Data &= 0x0f;
- LCD_Data |= temp;
- bitclr(P2OUT, RS); //set LCD to CMD mode
- _E(); //toggle E for LCD
- }
- /*---------- WLASNE FUNKCJE -------------*/
- void printFloat(float number) {
- char array[32];
- sprintf(array, "%f", number);
- for (int i = 0; i < 32; i++) {
- if (i == 17) SEND_CMD(DD_RAM_ADDR2);
- SEND_CHAR(array[i]);
- }
- }
- /* KONIEC WLASNYCH FUNKCJI*/
- ///KONIEC FUNKCJI------------------------------------------------------
- ///_____________M A I N___________________________________
- void main(void) {
- WDTCTL = WDTPW + WDTHOLD; // zatrzymanie WDT
- InitPortsLcd(); // inicjalizacja portów
- InitLCD(); // inicjalizacja LCD
- clearDisplay(); // czyszczenie LCD
- SEND_CMD(CG_RAM_ADDR);
- printFloat(32.323232f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement