0% found this document useful (0 votes)
4 views6 pages

Include

The document is a C program for a PIC18F4550 microcontroller that sets up an LCD display and handles button interrupts. It defines functions for initializing the LCD, sending commands and data, and responding to button presses with different display patterns. The main loop waits for a button press and displays messages based on the state of the buttons, utilizing interrupts for real-time response.

Uploaded by

g-13563010
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Include

The document is a C program for a PIC18F4550 microcontroller that sets up an LCD display and handles button interrupts. It defines functions for initializing the LCD, sending commands and data, and responding to button presses with different display patterns. The main loop waits for a button press and displays messages based on the state of the buttons, utilizing interrupts for real-time response.

Uploaded by

g-13563010
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <p18f4550.

h>

#include <delays.h>

void 1cd_setup(void);

void BTN1_Interrupt(void);

void 1cd_cmd(unsigned char value);

void 1cd_data(unsigned char value);

void chk_isr(void);

/**V E C T O R R E M A P P I N G

***************************************/

extern void _startup (void); //See c018i.c in yourC18 compiler dir

#pragma code _RESET_INTERRUPT_VECTOR =0x000800

void _reset (void)

_asm goto _startup _endasm

#pragma code

#pragma code _HIGH_INTERRUPT_VECTOR = 0x000808

void _high_ISR (void)

chk_isr();

//#pragma code _LOW_INTERRUPT_VECTOR = 0x000818

//void _low_ISR (void)

// {

// ;

// }

#pragma code
//=================ISR CHECKING ===================================================

#pragma interrupt chk_isr

void chk_isr (void)

if (INTCON3bits.INT2IF ==1)

BTN1_Interrupt();

//==================USER
PROGRAM===================================================

#define data_port PORTD

#define rs_pin PORTEbits.RE1

#define e_pin PORTEbits.RE2

#define BTN1 PORTBbits.RB2

#define BTN2 PORTBbits.RB3

//PATTERN 1

unsigned char Line1a[] = "BUTTON2 ";

unsigned char Line2a[] = " ";

//PATTERN 2

unsigned char Line1b[] = " ";

unsigned char Line2b[] = " BUTTON2";

//PATTERN 3 ---Interrupt

unsigned char Line1c[] = " INTERRUPT ";

unsigned char Line2c[] = " at BUTTON 1 ";

unsigned char i;

void main (void)

{
1cd_setup();

//HARDWARE CONFIGURATION-----------------------------------------

ADCON1=0b00001101; //AN0 and AN1 as analog pin

[Link]=0; //enable pull-up resistor at PORTB

TRISBbits.TRISB2 = 1; //BTN1 as input

TRISBbits.TRISB3 = 1; //BTN2 as input

//INTERRUPT CONFIGURATION-----------------------------------

INTCON2bits.INTEDG2 = 0 //H-L

transition

INTCON3bits.INT21E = 1; //INT2

enable

[Link] = 1 ; //Global Int

Enable

while(BTN2==1); //wait until BTN 2 is pressed

while (1)

{ //PATTERN 1

//Display Line1

1cd_cmd(0x80); //Set DDRAM Address

for (i = 0; i<16; i++

1cd_data(Line1a[i];

//Display Line2

1cd_cmd(0xC0); //Set DDRAM Address

1cd_data(Line2a[i];

Delay10KTCYx(250); //delay 0.5s


Delay10KTCYx(250); //delay 0.5s

//PATTERN 2

//Display Line1

1cd_cmd(0X80); //Set DDRAM Address

for (i = 0; i <16; i++

1cd_data{Line1b[i]);

//Display Line2

1cd_cmd(0xC0);

for (i = 0; i<16; i++)

1cd_data(Line2b[i]);

Delay10KTCYx(250);

Delay10KTCTx(250);

void BTN1_Interrrupt(void)

//PATTERN 3

//Display Line1==================================

1cd_cmd(0x80); //Set DDRAM Address

for(i = 0; i<16; i++

1cd_data(Line1c[i]);

//Display Line2===================================

1cd_cmd(0xC0); //Set DDRAM Address

for (i =0; i<16; i++)

{
1cd_data(Line2c[i])

while(BTN1==0);

INTCON3bits.INT2IF =0;

void 1cd_setup(void)

TRISD =0 ; //Configured

PORTD as Output

TRISEbits.TRISE1 = 0; //PORTE1 as output ->RS pin

TRISEbits.TRISE2 = 0; //porte2 as output -> E pin

[Link]=0; //ADC OFF

ADON1=0b00001101; //AN0 and AN1 are configured as ADC

pins

e_pin =0; //prepare to

enable idle low

Delay1KTCYx(50); //Delay 10ms

1cd_cmd(0x38); //Function Set =LCD

2 lines,5x7 dot

Delay1KTCTx(50) //Dely 10ms

1cd_cmd(0x0E); //display on,cursor

on

1cd_cmd(0x01); //clear LCD

1cd_cmd(0x06); //shift cursor right

void 1cd_cmd(unsigned char value)

data_port = value; //COMMAND SET


rs_pin = 0; //command mode

e_pin =1 ; //enable in

active state

Delay1KTCYx(5); //delay 1ms

e_pin = 0; //strobe

enable pin

Delay1KTCYx(25); //delay 5ms for execution

time

void 1cd_data(unsigned char value)

data_port = value; //DISPLAY DATA

rs_pin =1 ; //Data Mode

e_pin =1; //enable in

active state

Delay1KTCYx(5); //delay 1ms

e_pin =0; //strobe

enable pin

Delay1KTCYx(25); //delay 5ms for execution

time

You might also like