Browse Source

codigo y esquematico

master
griceldacc 1 year ago
parent
commit
1542312133
1 changed files with 168 additions and 0 deletions
  1. +168
    -0
      Código para inilización de LCD.c

+ 168
- 0
Código para inilización de LCD.c View File

@ -0,0 +1,168 @@
#include <msp430fr6989.h>
//GPIO definitions
#define CSBdefinition P1SEL1 |= BIT4 // Configure UCA0STE (slave select)
#define CLKdefinition P1SEL1 |= BIT5 // Configure UCA0CLK
#define SIMOdefinition P2SEL0 |= BIT0 // Configure UCA0SIMO/TXD
//Output configuration
#define DDRP1 P1DIR = 0x78; // 0111 1000
#define DDRP2 P1DIR |= BIT0;
/////////////////////////////////////////
#define RST_0 P1OUT &= ~BIT3
#define RST_1 P1OUT |= BIT3
#define CSB_0 P1OUT &= ~BIT4
#define CSB_1 P1OUT |= BIT4
#define RS_0 P1OUT &= ~BIT6
#define RS_1 P1OUT |= BIT6
#define SI_0 P2OUT &= ~BIT0
#define SI_1 P2OUT |= BIT0
// Global variables
unsigned char text1[] = {"Hi :D "};
unsigned char text2[] = {"It's done! "};
unsigned int position;
//**************************
// MSP430F59xx Demo - eUSCI_A0, SPI 4-Wire Master
//
// Description: SPI master send data to SPI slave using 4-wire mode.
// ACLK = 32.768kHz, MCLK = SMCLK = DCO ~1MHz. BRCLK = ACLK/2
//
//
// MSP430FR6989
// -----------------
// /|\| XIN|-
// | | | 32KHz Crystal
// --|RST XOUT|-
// | |
// | P2.0|-> Data Out (UCA0SIMO)
// | |
// | P1.3|-> RST LCD
// | P1.6|-> RS LCD
// | P1.5|-> Serial Clock Out (UCA0CLK)
// | P1.4|-> Slave Select (UCA0STE)
// | |
//
// William Goh
// Texas Instruments Inc.
// April 2014
// Built with IAR Embedded Workbench V5.60 & Code Composer Studio V6.0
//**************************
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Function initialization
void initLCD();
void initSPI();
void display();
void wData(unsigned char d);
void wCommand(unsigned char c);
volatile unsigned char TXData;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode to activate
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Pin configuration
CSBdefinition; // Configure UCA0STE (slave select)
CLKdefinition; // Configure UCA0CLK
SIMOdefinition; // Configure UCA0SIMO/TXD
PJSEL0 |= BIT4 | BIT5; // For XT1
DDRP1;
DDRP2;
initSPI();
initLCD();
__delay_cycles(50);
display();
__delay_cycles(50);
while(1){
}
}//main
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void initSPI(void){
// Configure USCI_A0 for SPI operation
UCA0CTLW0 = UCSWRST; // **Put state machine in reset**
UCA0CTLW0 |= UCSSEL__SMCLK; // Choose SMLCK (1MHz)
UCA0BR0 = 0x04;//4 // Set prescaler to 8 to get SCLK=125kHz
UCA0BR1 = 0;
UCA0MCTLW = 0;
// By default -> 4-pin, 8-bit SPI master
UCA0CTLW0 |= UCMST; // Master mode
UCA0CTLW0 |= UCSYNC; // Synchronous mode
UCA0CTLW0 |= UCCKPL; // Clock polarity high
UCA0CTLW0 |= UCMSB; // MSB first (Most Significant Bit)
UCA0CTLW0 |= UCMODE_2; // 4-pin SPI with UCxSTE active high
UCA0CTLW0 |= UCSTEM; // Generate the enable signal for a 4-wire slave
UCA0CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
UCA0IE |= UCTXIE; // Enable USCI_A0 TX interrupt
UCA0IFG &= ~UCTXIFG;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Initialize the LCD
void initLCD(){
RST_0; //reset
__delay_cycles(2);
RST_1; //end reset
__delay_cycles(20);
wCommand(0x30); //wake up
__delay_cycles(2);
wCommand(0x30); //wake up
wCommand(0x30); //wake up
wCommand(0x39); //function set
wCommand(0x14); //internal osc frequency
wCommand(0x56); //power control
wCommand(0x6D); //follower control
wCommand(0x70); //contrast
wCommand(0x0C); //display on
wCommand(0x06); //entry mode
wCommand(0x01); //clear
__delay_cycles(100);
}
void wCommand(unsigned char c){
CSB_0; //CSB active
RS_0; //Command/Instruction
UCA0TXBUF = c;
CSB_1; //CSB disabled
__delay_cycles(200);
}
void wData(unsigned char d){
CSB_0; //CSB active
RS_1; //Data
UCA0TXBUF = d;
CSB_1; //CSB disabled
}
void display(){
int a;
wCommand(0x80);
for(a=0; a<16; a++){
wData(text1[a]);
}
wCommand(0xC0);
for(a=0; a<16; a++){
wData(text2[a]);
}
}

Loading…
Cancel
Save