electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » Microcontrollers and Programmable Logic
The program of driving OLED by PIC18F13K22
Post new topic   Reply to topic Moderators: State Machine
Page 1 of 1 [1 Post]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
ailex1995



Joined: Apr 13, 2017
Posts: 3
Location: china

PostPosted: Thu Apr 13, 2017 2:17 am    Post subject: The program of driving OLED by PIC18F13K22
Subject description: programming,hardware
Reply with quote  Mark this post and the followings unread

Good afternoon~all, I met some troubles when I am working on the program about driving OLED by PIC18F13K22. Does anyone here can help me out?
Look! The program I wrote is as followings:
Code:
void init_fosc(void)
{
OSCCON = 0xF7;//16MHZ
}
void init_gpio(void)
{
     ANSEL=0x00;//inputting enabled digital
     ANSELH = 0x00;
     PORTB=0;
     LATB =0;
     TRISB =0xFF;

PORTC=0;
LATC=0;
TRISC =0x00;
}
void init_i2c_master()
{
    TRISB4 = input;
    TRISB6 = input;
    SSPCON1bits.SSPM0 = 0;
    SSPCON1bits.SSPM1 = 0;
    SSPCON1bits.SSPM2 = 0;
    SSPCON1bits.SSPM3 = 1;// I2C Master mode ,clock=Fosc/(4*(SSPxADD+1))
    SSPSTATbits.SMP = 0;//enabled slew rate: under the speed 400khz
    SSPADD = 0x09;//SCL CLOCK Frequency 400KHZ
    SSPCON1bits.SSPEN = 1;
}
void i2c_master_tx(unsigned char tx_deviceaddr,unsigned char tx_resaddr,unsigned char tx_data)
{   
     PIR1bits.SSPIF = 0;//the software need to set 0
    SSPCON2bits.SEN = 1;//the start conditions
    while(SSPCON2bits.SEN == 1);//SEN hardware will reset after finishing the start conditions
    // PIR1bits.SSPIF = 1;   Setting 1 by hardware
   
     
    SSPBUF = tx_deviceaddr;//the device site
    while(ACKSTAT);  // ~ACK
    while(PIR1bits.SSPIF == 0);
    PIR1bits.SSPIF = 0;//the software need to set 0
   
   
    SSPBUF = tx_resaddr;//writing the register which need to order
    while(ACKSTAT);  // ~ACK
    while(PIR1bits.SSPIF == 0);
    PIR1bits.SSPIF = 0;
   
   
    SSPBUF = tx_data;//writing data
while(ACKSTAT);  // ~ACK
    while(PIR1bits.SSPIF == 0);
    PIR1bits.SSPIF = 0;
   
     
    SSPCON2bits.PEN = 1;//Stop condition
}


I have also writen the OLED shows and initialization as well as the I2C agreement of hardware. It can operate perfectly by analogue I2C in the 51 SCM. Why can’t it communicate by using simulation and the I2C of hardware on PIC ?
This is the PIC18F13K22's datasheet: http://www.kynix.com/uploadfiles/pdf65976/PIC18F13K22-E2fML_965602.pdf ,please have a look if needed.

Thank you in advance!
Have a nice day~
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: State Machine
Page 1 of 1 [1 Post]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Microcontrollers and Programmable Logic
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use