Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PIC16F18877 Configuration Bit Settings
- // 'C' source line config statements
- // CONFIG1
- #pragma config FEXTOSC = OFF // External Oscillator mode selection bits (Oscillator not enabled)
- #pragma config RSTOSC = HFINT1 // Power-up default value for COSC bits (HFINTOSC (1MHz))
- #pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
- #pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
- #pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit (FSCM timer enabled)
- // CONFIG2
- #pragma config MCLRE = ON // Master Clear Enable bit (MCLR pin is Master Clear function)
- #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
- #pragma config LPBOREN = OFF // Low-Power BOR enable bit (ULPBOR disabled)
- #pragma config BOREN = ON // Brown-out reset enable bits (Brown-out Reset Enabled, SBOREN bit is ignored)
- #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices)
- #pragma config ZCD = OFF // Zero-cross detect disable (Zero-cross detect circuit is disabled at POR.)
- #pragma config PPS1WAY = ON // Peripheral Pin Select one-way control (The PPSLOCK bit can be cleared and set only once in software)
- #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)
- // CONFIG3
- #pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
- #pragma config WDTE = OFF // WDT operating mode (WDT Disabled, SWDTEN is ignored)
- #pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required)
- #pragma config WDTCCS = SC // WDT input clock selector (Software Control)
- // CONFIG4
- #pragma config WRT = OFF // UserNVM self-write protection bits (Write protection off)
- #pragma config SCANE = available// Scanner Enable bit (Scanner module is available for use)
- #pragma config LVP = ON // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/Vpp pin function is MCLR.)
- // CONFIG5
- #pragma config CP = OFF // UserNVM Program memory code protection bit (Program Memory code protection disabled)
- #pragma config CPD = OFF // DataNVM code protection bit (Data EEPROM code protection disabled)
- // #pragma config statements should precede project file includes.
- // Use project enums instead of #define for ON and OFF.
- #include <xc.h>
- #include <stdint.h>
- #include <stdio.h>
- // LCD module connections
- #define LCD_RS PORTCbits.RC2
- #define LCD_EN PORTCbits.RC3
- #define LCD_D4 PORTCbits.RC4
- #define LCD_D5 PORTCbits.RC5
- #define LCD_D6 PORTCbits.RC6
- #define LCD_D7 PORTCbits.RC7
- #define LCD_DATA_PORT PORTC
- #define _XTAL_FREQ 4000000
- // Function prototypes
- void LCD_Init();
- void LCD_Cmd(unsigned char);
- void LCD_Char(unsigned char);
- void LCD_String(const char*);
- void LCD_Clear();
- void LCD_Send(int RS,unsigned char data);
- void main(void) {
- char name[16] = "Aung Win Htut";
- int i = 32;
- LCD_Init();
- LCD_Clear();
- while (1) {
- i++;
- if(i>127)
- {
- i = 32;
- }
- LCD_Clear();
- LCD_Cmd(0x00);
- LCD_Char((char)i);
- __delay_ms(100);
- }
- return;
- }
- void LCD_Init() {
- TRISC = 0x00; //all C port pins are output
- __delay_ms(15);
- LCD_Cmd(0x02); // Return home
- LCD_Cmd(0x28); // 4-bit mode - 2 line display - 5x7 font
- LCD_Cmd(0x0C); // Display ON - Cursor OFF - Blink OFF
- LCD_Cmd(0x06); // Increment cursor - No shift
- LCD_Cmd(0x80); // Address DDRAM with 0 offset 80h
- }
- void LCD_Cmd(unsigned char command) {
- LCD_Send(0,command);
- }
- void LCD_Char(unsigned char data) {
- LCD_Send(1,data);
- }
- void LCD_Send(int RS,unsigned char data)
- {
- LCD_RS = RS; // Data mode data = 1101, 1001
- LCD_DATA_PORT = (LCD_DATA_PORT & 0x0F) | (data & 0xF0); // Send higher nibble 1101,0000
- LCD_EN = 1; // Enable pulse
- __delay_us(1);
- LCD_EN = 0;
- __delay_us(200);
- LCD_DATA_PORT = (LCD_DATA_PORT & 0x0F) | ((data << 4) & 0xF0); // Send lower nibble 1001,0000
- LCD_EN = 1; // Enable pulse
- __delay_us(1);
- LCD_EN = 0;
- __delay_ms(2);
- }
- void LCD_String(const char* text) {
- while (*text != '\0') {
- LCD_Char(*text++);
- }
- }
- void LCD_Clear() {
- LCD_Cmd(0x01); // Clear display
- __delay_ms(2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement