Sie sind auf Seite 1von 18

START

Initialize variables TRISD=0


TRISB6 and B7 to 0 And INTCON = 0x00

Main Flow Chart Initialize LCD ALCD_Init()


Send Test Message ALCD_Message

GfnUsartPinConfigure() _ Configure USART


GfnBuadRateSet(); - Baud Rate 9600 select
GfnUsartInit(); - Initialize USART

Delay

CAN_Port_Init(); - Initialise CAN Ports


InitECAN();
Send message CAN Initialised using
GfnUsartTransmitString("CAN Initialised\n\r")
Send Message to ALCD_message(…)

No
If CAN Receive Data Wait
is available

Yes

Call GfnUsartTransmitString to show Message Received


Call ALCD_Message to Display Message Received
Pass on the values to temp_SIDX…D0..D7 variables and
Call GfnUsartTransmitString to show Received Messages

IF EOC=1 , then Conversion from Analog


i/p to digital/p is done
No
END Chk if temp_SIDH and
temp_SIDL are set

Convert temp_D0 and D1 to ASCII (add 48 )

ALCD_Message( 0xC0, "D0 = " ) – Go to 2nd line of LCD and


display D0

ALCD_Message( 0xC8, "D1 = " ) – Go to 2 nd line char 8 of


LCD and display D1

No
Chk if temp_SIDH and
END temp_SIDL are set for 0x12 and
0xc00 respectively
Function void ALCD_Init( void )

START

Yes
ALCD initializations are done here
TRISB = 0x00 TRISD0 = 0 TRISD1 = 0
Call ALCD_Comm( 0x28 )Select 2 Lines and 5x7 matrix
Call ALCD_Comm( 0x0E )for Display ON, Cursor blinking
Call ALCD_Comm( 0x01) for Clear display Screen
Call ALCD_Comm( 0x06) for Shift cursor right

END

Function void ALCD_Message( char addr, char *data_ptr )

START

To Display ALCD Message


Point Char data ptr to receive the string
Addr value is = address of LCD display

Yes
Data ptr = NULL END

No

Increment to next char

Call Delay
Function void ALCD_Comm( char comm_data )

START

To Send command to ALCD


Receive comm_data
ALCD_RS = 0 --- Enable Command Mode
ALCD_Enable = 1 – Enable LCD Display
ALCD_R1_W0 = 0 – Enable Write Mode

Call delay

Disable ALCD after sending Command

END
Function void ALCD_Data( char disp_data )

START

To Send command to ALCD


Receive comm_data
ALCD_RS = 1 --- Enable Data Mode
ALCD_Enable = 1 – Enable LCD Display
ALCD_R1_W0 = 0 – Enable Write Mode

Call delay

Disable ALCD after sending Command

END
Function void Delay_Little( void )

START

INT I = 0

No
I = 1000
Increment I

Yes

END
Function void MSDelay( unsigned int Milli_Sec )

START

Read Milli_Sec

INT y = 0, x=0

Yes

END Is x = Milli_sec
Increment x
No

INT y = 0

No
I =Y=
1000
180
Increment y

Yes
Function void GfnUsartPinConfigure(void)

START

Yes
initializations are done here

RCSTA |= 0x80 Enable the Serial Port.

TRISC &= 0xBF Make Tx pin as output

TRISC |= 0x80 Make Rx pin as Input

END

Function void GfnBuadRateSet(void)

START

Baud Rate setting is done here

SPBRG = 25 - Assign SPB Reg to 25 which sets the


Baud Rate to 9.6kps

END
Function void GfnUsartInit(void)

START

Initialize USART for Transmission

TXSTA &= 0xBF -- Clear TX9


TXSTA &= 0xEF -- Clear SYNC bit
TXSTA &= 0xFB -- Clear BRGH
TXSTA |= ~0xFB -- Set BRGH
TXSTA |= 0x20 -- Set TXEN i.e. ,Transmission Enabled

Initialize USART for Reception


RCSTA &= 0xBF -- Clear
RCSTA |= 0x10 -- Then Set to Enable Continuous Receive

END
Function GfnUsartTransmitt(char byte)

START

Initialize variable i = 0
Initialize CHARACTER TXREG to be received
variable

Wait till the TXIF is cleared

Wait till PIR1 is cleared

END
Function GfnUsartTransmitString(char *str)

START

Initialize int variable i = 0


Initialize CHARACTER TXREG to be received
variable

Wait till the TXIF is cleared

Wait till PIR1 is cleared

Increment to the next character to be


transmitted

END

Function void CAN_Port_Init(void)

START

Set TRISB for Transmission – Tx pin as o/p port

Set TRISB for Reception – Rx pin as i/p port

Function void InitECAN(void)


END
START

Initialize INT variable i = 0

Enter CAN module into config mode


CANCON = 0x80

Wait till CANSTAT is enabled

Initialize CAN Timing


To 25Kbps @ 4MHz
SJW = 1, Phase Seg1 = 3, Phase Seg2 = 3, Prop Seg = 1
This is done by
BRGCON1 = 0b00000001
BRGCON2 = 0b10010000
BRGCON3 = 0b00000010

Initialize CAN Timing


To 25Kbps @ 4MHz
SJW = 1, Phase Seg1 = 3, Phase Seg2 = 3, Prop Seg = 1
This is done by
BRGCON1 = 0b00000001
BRGCON2 = 0b10010000
BRGCON3 = 0b00000010

Initialize Receive Masks


The first mask is used that accepts all SIDs and no EIDs
The follo values are set
RXM0EIDH = 0x00
RXM0EIDL = 0x00
RXM0SIDH = 0xFF This is for Standard ID FILTER setting
RXM0SIDL = 0xE0
RXF1EIDH = 0x00
SetRXF1EIDL = 0x00Buffers
Receive Mode
RXF1SIDH
RXB0CON = 0x00= 0x32
Switch to Normal
RXF1SIDL ENDmode
= 0xC0CAN wait CANCON = 0x00
RXB1CON = 0x00
Function void ECAN_Transmit(void) - To Check for Transmission
START

Initialize Registers for transmission


TXB0EIDH = 0x00
TXB0EIDH = 0x00
TXB0EIDL = 0x00
TXB0SIDH = 0x01
TXB0SIDL = 0xC0
TXB0DLC = 0x03

Assign values to

TXB0D0…..D7

Set the TXREQ bit i.e.,buffer


TXB0CON - to start Transmission

END

Das könnte Ihnen auch gefallen